How to fix "Interrupted system call"?

here is the problem,some time i debug the program,the main thread is panicked,the error message is "Os { code: 4, kind: Interrupted, message: "Interrupted system call" }" .
i check the message of stack backtrace:

   0:        0x10eed179f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h83d53b696ac99295
   1:        0x10eef349e - core::fmt::write::hf81c429634e1f3ed
   2:        0x10eecb697 - std::io::Write::write_fmt::had2a3b01a2c037b5
   3:        0x10eed37fa - std::panicking::default_hook::{{closure}}::ha991e4eca34b4afa
   4:        0x10eed353c - std::panicking::default_hook::h722aa3f5c1c31788
   5:        0x10eed3dc8 - std::panicking::rust_panic_with_hook::h2cd47f71d6d55501
   6:        0x10eed3992 - rust_begin_unwind
   7:        0x10eeffe1f - core::panicking::panic_fmt::h299f54c72477a62a
   8:        0x10eeffd25 - core::result::unwrap_failed::hf7a9e1e19e331f17
   9:        0x10ec3d724 - core::result::Result<T,E>::unwrap::h9975a074967eec7d
  10:        0x10eb3eaf1 - roomserver::net::tcp_server::new::h8f40227fb3e7e9ef
  11:        0x10eb3f493 - roomserver::init_tcp_server::h78d2942b8cb2f489
  12:        0x10eb3f3ea - roomserver::main::hcba912d14543799c
  13:        0x10eb4774e - std::rt::lang_start::{{closure}}::hfd56a12f21fe1ec1
  14:        0x10eed4129 - std::rt::lang_start_internal::h1069bf3e81ece2dd
  15:        0x10eb47731 - std::rt::lang_start::hd02c25651ee7fbc4
  16:        0x10eb3f602 - main

the "roomserver::net::tcp_server::new" is a function to create a tcp server struct and run.

but it's ok in release,only when i debug occur this kind of error.
i guess maybe because of breakpoint make main thread blocked,but OS try to send signal to a blocked thread causes errors to occur? i do not know.
so how to fix it?
thanks for advices!

Some system calls, such as read and write in POSIX can be interrupted (this especially happens in case of networking, when receiving a signal). The application needs to handle this, usually by ignoring the error and re-issuing the system call.
(see for example this implementation in write_all in the standard lib: https://github.com/rust-lang/rust/blob/master/src/libstd/io/mod.rs#L1406)

yes,i have handler read and write Result,if err,print it,but there is no print.

That is unexpected. Maybe it's being returned in different place then where you expect it? (note that not only read and write can be interrupted, but also, say, accept and connect). You might want to build in debug mode to see line numbers in the backtrace.

1 Like

thanks ,i have find out where the problem is,i use mio build my tcp server, i focus on write and read but ignore the mio component.
Poll of mio ,it's return a Result<()>,but i direct unwrap it,
thanks for your reply^_^

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.