Skip to content

panics in print-macros when Linux process looses terminal #92989

@kolbma

Description

@kolbma

I tried this code:

use std::time::Duration;

fn main() {
    loop {
        println!("Hello, world!");
        std::thread::sleep(Duration::from_millis(100));
    }
}

Here is a complete cargo project: https://github.com/kolbma/rocket-issues/tree/main/println

There you can read these steps for reproducing:

Run this in debugger.

Go to terminal of debugger.

Pause execution (CTRL + Z).

bg to run it in background

Close the terminal e.g. exit or STRG + D

The debugger jumps immediately in a panic in std::io::stdio::print_to.

I expected to see this happen: The process should continue to run as usually other processes do, too.

Instead, this happened: The process panics

write!(std::io::stdout(), "Hello world!\n").unwrap() does not panic.

Meta

rustc --version --verbose:

rustc 1.58.0 (02072b482 2022-01-11)
binary: rustc
commit-hash: 02072b482a8b5357f7fb5e5637444ae30e423c40
commit-date: 2022-01-11
host: x86_64-unknown-linux-gnu
release: 1.58.0
LLVM version: 13.0.0

or

rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-unknown-linux-gnu
release: 1.51.0
LLVM version: 11.0.1
Backtrace

rust_panic (@rust_panic:7)
rust_panic_with_hook (@std::panicking::rust_panic_with_hook::h71e6a073d87de1f5:105)
{{closure}} (@std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::hd549436f6bb6dbb8:42)
__rust_end_short_backtrace<closure-0,!> (@std::sys_common::backtrace::__rust_end_short_backtrace::h4e5f4b72b04174c3:10)
begin_panic_handler (@rust_begin_unwind:21)
begin_panic_fmt (@std::panicking::begin_panic_fmt::h818c3c917eaeb432:16)
std::io::stdio::print_to (@std::io::stdio::_print::hfdac4ecf8a146755:171)
_print (@std::io::stdio::_print::hfdac4ecf8a146755:77)
main (/home/makolb/Source/Repos/rocket-issues/println/src/main.rs:5)
call_once<fn(),()> (/home/makolb/.rustup/toolchains/1.51.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227)
__rust_begin_short_backtrace<fn(),()> (/home/makolb/.rustup/toolchains/1.51.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:125)
{{closure}}<()> (/home/makolb/.rustup/toolchains/1.51.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:66)
core::ops::function::impls::_$LT$impl$u20$core..ops..function..FnOnce$LT$A$GT$$u20$for$u20$$RF$F$GT$::call_once (@std::rt::lang_start_internal::hd5b67df56ca01dae:176)
std::panicking::try::do_call (@std::rt::lang_start_internal::hd5b67df56ca01dae:174)
std::panicking::try (@std::rt::lang_start_internal::hd5b67df56ca01dae:174)
std::panic::catch_unwind (@std::rt::lang_start_internal::hd5b67df56ca01dae:174)
lang_start_internal (@std::rt::lang_start_internal::hd5b67df56ca01dae:174)
lang_start<()> (/home/makolb/.rustup/toolchains/1.51.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:65)
main (@main:12)
__libc_start_main (@__libc_start_main:62)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions