diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-11-24 10:55:17 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-11-24 21:22:19 -0800 |
| commit | 9fe8fc8836284643f13e148e3e8a09b643f3ff28 (patch) | |
| tree | 019e6d9c264802e986c7082f53bd1d3d9e7bee6a /src/libstd | |
| parent | 01b53817033ba3a3ec01685d30e4a8e7ce14ba0c (diff) | |
| download | rust-9fe8fc8836284643f13e148e3e8a09b643f3ff28.tar.gz rust-9fe8fc8836284643f13e148e3e8a09b643f3ff28.zip | |
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
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/logging.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libstd/logging.rs b/src/libstd/logging.rs index 1c464110ce0..4af6d1d53be 100644 --- a/src/libstd/logging.rs +++ b/src/libstd/logging.rs @@ -110,7 +110,11 @@ pub fn log(_level: u32, args: &fmt::Arguments) { match (*local).logger { // Use the available logger if we have one Some(ref mut logger) => return logger.log(args), - None => {} + None => { + let mut logger = StdErrLogger::new(); + logger.log(args); + (*local).logger = Some(logger); + } } } None => {} |
