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

fix: Output writing #804

Merged
merged 1 commit into from
Feb 28, 2023
Merged

fix: Output writing #804

merged 1 commit into from
Feb 28, 2023

Conversation

flub
Copy link
Contributor

@flub flub commented Feb 28, 2023

This simply delegates to eprintln! for writing output. This ensures
writes happen more synchronously and the flaky integration tests are
fixed.

While in theory these are blocking operations on the async executor,
this is acceptable because:

  • We already use println!() without any problems. Arguably this is
    more of an issue since we also write data to stdout but it isn't
    because we don't do that at the same time.

  • We print a small number of messages, not large amounts of data. Any
    blocking from this will be small.

  • This acquires a sync mutex while writing, that's fine because it is
    acquired and released in the same chunk of async code and not held
    across await points. This is unlikely to block much as only main
    writes and only one write happens at a time.

  • When logging via tracing is enabled this will also end up logging on
    here and will compete for the lock. This is slightly higher
    contention but doesn't really interfere with the logging here.

This simply delegates to eprintln! for writing output.  This ensures
writes happen more synchronously and the flaky integration tests are
fixed.

While in theory these are blocking operations on the async executor,
this is acceptable because:

- We already use println!() without any problems.  Arguably this is
  more of an issue since we also write data to stdout but it isn't
  because we don't do that at the same time.

- We print a small number of messages, not large amounts of data.  Any
  blocking from this will be small.

- This acquires a sync mutex while writing, that's fine because it is
  acquired and released in the same chunk of async code and not held
  across await points.  This is unlikely to block much as only main
  writes and only one write happens at a time.

- When logging via tracing is enabled this will also end up logging on
  here and will compete for the lock.  This is slightly higher
  contention but doesn't really interfere with the logging here.
Copy link
Contributor

@rklaehn rklaehn left a comment

Choose a reason for hiding this comment

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

Fine by me.

@flub
Copy link
Contributor Author

flub commented Feb 28, 2023

I'll wait for approval by @ramfox as well since I inadvertently stepped on their PR.

// Print the formatted string to the console with a newline
message.push('\n');
tokio::io::stderr().write_all(message.as_ref()).await.unwrap();
eprintln!($fmt $(, $args)*);
Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me, until this becomes an issue, lets just do this

@ramfox
Copy link
Contributor

ramfox commented Feb 28, 2023

🔥

@flub flub merged commit eb18a89 into main Feb 28, 2023
@flub flub deleted the flub/fix-output-write branch February 28, 2023 17:34
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.

None yet

4 participants