Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Prevent print panics when using TLS #29491

Merged
merged 1 commit into from
Nov 6, 2015

Conversation

alexcrichton
Copy link
Member

Currently if a print happens while a thread is being torn down it may cause a
panic if the LOCAL_STDOUT TLS slot has been destroyed by that point. This adds a
guard to check and prints to the process stdout if that's the case (as we do for
if the slot is already borrowed).

Closes #29488

Currently if a print happens while a thread is being torn down it may cause a
panic if the LOCAL_STDOUT TLS slot has been destroyed by that point. This adds a
guard to check and prints to the process stdout if that's the case (as we do for
if the slot is already borrowed).

Closes rust-lang#29488
@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

//
// If, however, the actual I/O causes an error, we do indeed panic.
let result = match LOCAL_STDOUT.state() {
LocalKeyState::Uninitialized |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOCAL_STDOUT.with would initialize data, so I think this branch should go together with the next arm.

EDIT: this is also fine, because if stdout ends up actually changed from the global default, it would also get initialised.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this branch could actually go either way, but I figured that we may as well avoid initializing TLS if we're not gonna use it anyway (e.g. as you also mentioned it'd just go to the same place regardless)

@nagisa
Copy link
Member

nagisa commented Oct 31, 2015

LGTM. Would r+.

@sfackler
Copy link
Member

Do we still use LOCAL_STDOUT? Can we kill it instead?

@alexcrichton
Copy link
Member Author

@sfackler currently it's used to still capture the stdout of tests, but that's the only use that I know of.

@alexcrichton
Copy link
Member Author

ping r? @brson

@brson
Copy link
Contributor

brson commented Nov 5, 2015

@bors r+

@bors
Copy link
Contributor

bors commented Nov 5, 2015

📌 Commit 8588654 has been approved by brson

@bors
Copy link
Contributor

bors commented Nov 6, 2015

⌛ Testing commit 8588654 with merge 7512808...

bors added a commit that referenced this pull request Nov 6, 2015
Currently if a print happens while a thread is being torn down it may cause a
panic if the LOCAL_STDOUT TLS slot has been destroyed by that point. This adds a
guard to check and prints to the process stdout if that's the case (as we do for
if the slot is already borrowed).

Closes #29488
@bors bors merged commit 8588654 into rust-lang:master Nov 6, 2015
@alexcrichton alexcrichton deleted the avoid-stdio-tls branch January 21, 2016 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants