#thread 'tokio-runtime-worker' has overflowed its stack

1 messages · Page 1 of 1 (latest)

austere lynx
#

I'm getting the above error when trying to connect a tcp_stream to a server that is NOT running

    let mut handle_guard = self.handles.lock().await;

    if handle_guard.is_none() {
       let tcp_stream = match TcpStream::connect(IP).await {
        Ok(stream) => stream,
        Err(e) => {
          println!("error connecting to tcp stream: {}", e);
          return Err(Error::from(e));
        }
      };

      let (rh, wh) = tcp_stream.into_split();
      let writer = tokio::spawn(command_writer(rx, wh));
      let reader = tokio::spawn(response_listener(rh, self.app_handle.clone()));

      *handle_guard = Some((reader, writer));
    }

the following logs show up

[2023-01-17][00:23:44][mio::poll][TRACE] registering event source with poller: token=Token(0), interests=READABLE | WRITABLE
[2023-01-17][00:23:46][mio::poll][TRACE] deregistering event source from poller
error connecting to tcp stream: No connection could be made because the target machine actively refused it. (os error 10061)

thread 'tokio-runtime-worker' has overflowed its stack
vagrant breach
#

hey @austere lynx, were you able to solve the problem? Iim getting the same error

austere lynx
#

I did solve it but it's been so long I don't remember the exact issue, I'll post my working code as an example and feel free to ask me any questions

#
  pub async fn get_desktop_connection(&self, app_handle: AppHandle) -> Result<(), Error> {
    let mut handle_guard = self.handles.lock().await;

    if handle_guard.is_none() {
      let (tx, rx) = mpsc::channel::<ChannelCommand>(32);
      let mut write_channel_sender_guard = self.write_channel_sender.lock().await;
      *write_channel_sender_guard = Some(tx.clone());
      let tcp_stream = match TcpStream::connect(IP).await {
        Ok(stream) => stream,
        Err(e) => {
          println!("Failed to connect to desktop stream");
          return Err(Error::Generic("Failed to create tcp stream".to_string()));
        }
      };
      let (rh, wh) = tcp_stream.into_split();
      let (rh, wh) = authorize(rh, wh).await?;

      let writer = tokio::spawn(command_writer(rx, wh));
      let reader = tokio::spawn(response_listener(rh, self.clone(), app_handle));

      *handle_guard = Some((reader, writer));

      return Ok(());
    }

    return Ok(());
  }
#

@vagrant breach

#

first part of the command_writer

pub async fn command_writer(mut rx: mpsc::Receiver<ChannelCommand>, write_half: OwnedWriteHalf) {
  let mut writer = BufWriter::new(write_half);
  info!("prepare to write");

  while let Some(command) = rx.recv().await {
  ...
  }
}