Skip to content

Commit 9fe8fc8

Browse files
committed
Cache a task's stderr logger
This is both useful for performance (otherwise logging is unbuffered), but also useful for correctness. Because when a task is destroyed we can't block the task waiting for the logger to close, loggers are opened with a 'CloseAsynchronously' specification. This causes libuv do defer the call to close() until the next turn of the event loop. If you spin in a tight loop around printing, you never yield control back to the libuv event loop, meaning that you simply enqueue a large number of close requests but nothing is actually closed. This queue ends up never getting closed, meaning that if you keep trying to create handles one will eventually fail, which the runtime will attempt to print the failure, causing mass destruction. Caching will provide better performance as well as prevent creation of too many handles. Closes #10626
1 parent 01b5381 commit 9fe8fc8

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/libstd/logging.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ pub fn log(_level: u32, args: &fmt::Arguments) {
110110
match (*local).logger {
111111
// Use the available logger if we have one
112112
Some(ref mut logger) => return logger.log(args),
113-
None => {}
113+
None => {
114+
let mut logger = StdErrLogger::new();
115+
logger.log(args);
116+
(*local).logger = Some(logger);
117+
}
114118
}
115119
}
116120
None => {}

src/test/run-pass/issue-10626.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-fast
12+
13+
// Make sure that if a process doesn't have its stdio/stderr descriptors set up
14+
// that we don't die in a large ball of fire
15+
16+
use std::os;
17+
use std::io::process;
18+
19+
fn main () {
20+
let args = os::args();
21+
if args.len() > 1 && args[1] == ~"child" {
22+
for _ in range(0, 1000) {
23+
error!("hello?");
24+
}
25+
for _ in range(0, 1000) {
26+
println!("hello?");
27+
}
28+
}
29+
30+
let config = process::ProcessConfig {
31+
program : args[0].as_slice(),
32+
args : [~"child"],
33+
env : None,
34+
cwd : None,
35+
io : []
36+
};
37+
38+
let mut p = process::Process::new(config).unwrap();
39+
println!("{}", p.wait());
40+
}

0 commit comments

Comments
 (0)