message: endlessly retry connection to devtools websocket
  Endlessly retry connection to preview's devtools websocket on `wrangler dev`. With exponential backoff.
diff: @@ -6,7 +6,7 @@ use futures_util::future::TryFutureExt;
  use futures_util::sink::SinkExt;
  use futures_util::stream::{SplitStream, StreamExt};
  -use crate::terminal::message::{Message, StdOut};
  +use crate::terminal::message::{Message, StdErr, StdOut};
  use protocol::domain::runtime::event::Event::ExceptionThrown;
  use tokio::net::TcpStream;
  use tokio::sync::mpsc;
  @@ -24,9 +24,7 @@ pub async fn listen(socket_url: Url) -> Result<(), failure::Error> {
  // we loop here so we can issue a reconnect when something
  // goes wrong with the websocket connection
  loop {
  - let (ws_stream, _) = connect_async(&socket_url)
  - .await
  - .expect("Failed to connect to devtools instance");
  + let ws_stream = connect_retry(&socket_url).await;
  let (mut write, read) = ws_stream.split();
  @@ -61,6 +59,36 @@ pub async fn listen(socket_url: Url) -> Result<(), failure::Error> {
  }
  }
  +// endlessly retry connecting to the chrome devtools instance with exponential backoff
  +async fn connect_retry(
  + socket_url: &Url,
  +) -> WebSocketStream<Stream<TcpStream, TlsStream<TcpStream>>> {
  + let mut wait_seconds = 2;
  + let mut failed = false;
  + loop {
  + match connect_async(socket_url).await {
  + Ok((ws_stream, _)) => {
  + if failed {
  + // only report success if there was a failure, otherwise be quiet about it
  + StdErr::success("Connected!");
  + }
  + return ws_stream;
  + }
  + Err(e) => {
  + failed = true;
  + StdErr::warn(&format!("Failed to connect to devtools instance: {}", e));
  + StdErr::warn(&format!(
  + "Will retry connection in {} seconds",
  + wait_seconds
  + ));
  + delay_for(Duration::from_secs(wait_seconds)).await;
  + wait_seconds = wait_seconds.pow(2);
  + StdErr::working("Retrying...");
  + }
  + }
  + }
  +}
  +
  async fn print_ws_messages(
  mut read: SplitStream<WebSocketStream<Stream<TcpStream, TlsStream<TcpStream>>>>,
  ) -> Result<(), failure::Error> {
  