-
Notifications
You must be signed in to change notification settings - Fork 61
Flush traces before dsc exits
#1438
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
Changes from 5 commits
eb44b9a
a5b2622
97d890d
af7e291
a2722a4
4e821c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,6 @@ use std::collections::HashMap; | |
| use std::env; | ||
| use std::io::{IsTerminal, Read, stdout, Write}; | ||
| use std::path::Path; | ||
| use std::process::exit; | ||
| use syntect::{ | ||
| easy::HighlightLines, | ||
| highlighting::ThemeSet, | ||
|
|
@@ -690,3 +689,29 @@ pub fn merge_parameters(file_params: &str, inline_params: &str) -> Result<String | |
| let merged = Value::Object(file_map); | ||
| Ok(serde_json::to_string(&merged)?) | ||
| } | ||
|
|
||
| /// Exit the process with the given code after flushing outputs | ||
| /// | ||
| /// # Arguments | ||
| /// | ||
| /// * `code` - The exit code to use when exiting the process | ||
| pub fn exit(code: i32) -> ! { | ||
| // Small delay to ensure async writes complete | ||
| std::thread::sleep(std::time::Duration::from_millis(50)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀 Seems like a workaround more than a solution...is there no way to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like I can call https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html#method.shutdown_timeout
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I can't use that outside of an async task running within the runtime. And it looks like tokio itself doesn't provide a way to wait tokio-rs/tokio#5369 So this workaround seems like the only approach
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andyleejordan any suggestions?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I take it back, it looks like a WorkerGuard flushes when dropped (https://docs.rs/tracing-appender/latest/tracing_appender/non_blocking/struct.WorkerGuard.html), so need to keep the guard and drop on exit.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spent too much time on this. Using a guard doesn't work because we're also using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, oh well. Love when "standard" libraries are broken. |
||
|
|
||
| // Force any pending writes to complete | ||
| if let Err(e) = std::io::stderr().flush() { | ||
| // Ignore BrokenPipe on stderr to avoid noisy exits in piped scenarios | ||
| if e.kind() != std::io::ErrorKind::BrokenPipe { | ||
| eprintln!("Failed to flush stderr: {}", e); | ||
| } | ||
| } | ||
| if let Err(e) = std::io::stdout().flush() { | ||
| // Ignore BrokenPipe on stdout to avoid noisy exits in piped scenarios | ||
| if e.kind() != std::io::ErrorKind::BrokenPipe { | ||
| eprintln!("Failed to flush stdout: {}", e); | ||
| } | ||
| } | ||
|
|
||
| std::process::exit(code); | ||
|
SteveL-MSFT marked this conversation as resolved.
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.