0

I am currently developing a little game in rust (I am a beginner). For this game I use threads to read and write on a TcpStream. The whole project compile without errors. I have use the macro "info!" everywhere in my project in order to debug it. When I launch the binary with RUST_LOG="info", my thread that listen on the TcpStream exits with the error :

thread 'Server listening thread' has overflowed its stack error: process didn't exit successfully: target\debug\server.exe (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW

This exit happens after the data read from stream. In this situation I am able to get some info output before a function call which is :

pub fn ask_shoot(tx: &mut Sender<Msg>, data: Data) {
    info!("Asking shoot");
    let msg: Msg = Msg::new(Event::EShoot, data.union);
    info!("Sending msg to myself: {}", msg);
    tx.send(msg).unwrap();
}

This function is called in my thread. The call to Msg::new(Event::EShoot, data.union); is also made I get an ifo! output from the new function, but I never get the info!("Sending msg to myself: {}", msg);

Whereas when I disable the environnmeant variable RUST_LOG my thread doesn't exit. So I am wondering what is going on as I want the info output for debugging. I have try to increase my stack size with (1024*1024*10) but this doesn't work. Do you have any lead ?

Edit: The crate I use for info is log with the crate env_logger My implementation of sdt::fmt::Display for Msg is :

impl fmt::Display for Msg {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "Event: {}, Data: {}", self.event, self.data)
        }
    }
Clément
  • 53
  • 6
  • 1
    It's probably relevant which crate your `info` is from. I.e. what crate(s) do you use to handle your logging. The `impl std::fmt::Display for Msg` might also be relevant if you wrote it yourself. Please [edit] your question to include those. – cafce25 Apr 16 '23 at 12:45
  • As requested I edit my post @cafce25 – Clément Apr 16 '23 at 14:34
  • 1
    Unfortunately that's not a [mre] either, please try to include everything necessary to reproduce the error, but remove anything that's not necessary. Most likely somewhere along your custom `Display` implementations you have something like `fn fmt(&self, f) -> Result { write!(f, "{}", self) }` which then inevitably overflows the stack. – cafce25 Apr 16 '23 at 14:55
  • Well, as @cafce25 said before, you probably has some error in one of your `Display` impls. Your `Msg::fmt()` looks fine, but that just calls `Display::fmt()` on `self.event` and `self.data` that you didn't show. I'm guessing that the problem is in that `self.data` thing, that coming from something called `union` is probably quite complex. – rodrigo Apr 17 '23 at 16:39

0 Answers0