Skip to content

Fix races in tracing-appender unit tests #737

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

Merged
merged 2 commits into from
Jun 12, 2020
Merged

Fix races in tracing-appender unit tests #737

merged 2 commits into from
Jun 12, 2020

Conversation

thekeys93
Copy link
Contributor

@thekeys93 thekeys93 commented May 26, 2020

I was able to reproduce the failures for logs_dropped_if_lossy on my machine when usnig loom.

Realized that the Worker calls recv and the only time we actually will increment the error_counter is when we have a write blocking on the call to write_all (called by the worker) and a messege buffered in NonBlocking crossbeam sender.

I added some sleeps after writes to avoid some races I saw.

For multi_threaded_writes, what likely is happening is that sometimes the last thread hasn't had a chance write to the queue, hence we now use recv_timeout instead of try_recv, to ensure there's more than enough time for the a message to be visible in the channel.

@thekeys93 thekeys93 requested review from hawkw and a team as code owners May 26, 2020 19:56
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

Going to go ahead and merge this because the flakiness is really getting old. We can try to do some additional test cleanup later.

Comment on lines +339 to +340
// Sleep a bit to prevent races.
thread::sleep(Duration::from_millis(200));
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a huge fan of tests that rely on load-bearing sleeps to work correctly. But, if there's no other solution, I'm fine with merging this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if this test is still being problematic. We can probably use some retry logic instead of sleeps here instead now that I think about it.

@hawkw hawkw merged commit a48e4e3 into tokio-rs:master Jun 12, 2020
ericjheinz pushed a commit to ericjheinz/tracing that referenced this pull request Jun 12, 2020
## Motivation

I was able to reproduce the failures for `logs_dropped_if_lossy` on my
machine when using loom.

Realized that the Worker calls `recv` and the only time we actually will
increment the error_counter is when we have a write blocking on the call
to `write_all` (called by the worker) and a messege buffered in
NonBlocking crossbeam sender.

## Solution

I added some sleeps after writes to avoid some races I saw.

For `multi_threaded_writes`, what likely is happening is that sometimes
the last thread hasn't had a chance write to the queue, hence we now use
`recv_timeout` instead of `try_recv`, to ensure  there's more than enough
time for the message to be visible in the channel.

Co-authored-by: Zeki Sherif <[email protected]>
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.

2 participants