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

[exporterhelper] Fix potential deadlocks in BatcherSender shutdown #10258

Merged

Conversation

dmitryax
Copy link
Member

Fixes #10255

@TylerHelmuth
Copy link
Member

I'm guessing I missed something since TestBatchSender_MergeOrSplit isn't passing anymore

@dmitryax dmitryax force-pushed the fix-batcher-shutdown-deadlock branch from 4ab3a33 to 25d9fb7 Compare May 29, 2024 23:33
Copy link

codecov bot commented May 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.46%. Comparing base (eaab76e) to head (0491e66).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10258   +/-   ##
=======================================
  Coverage   92.46%   92.46%           
=======================================
  Files         387      387           
  Lines       18264    18269    +5     
=======================================
+ Hits        16888    16893    +5     
  Misses       1029     1029           
  Partials      347      347           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dmitryax dmitryax force-pushed the fix-batcher-shutdown-deadlock branch from 25d9fb7 to 0491e66 Compare May 30, 2024 04:13
@dmitryax
Copy link
Member Author

TestBatchSender_MergeOrSplit is good. It's just an accidental debug output, removed #10261

The actual regression test was still failing. I updated the code, should be good now.

for i := 0; i < 10; i++ {
startWG.Add(1)
go func() {
startWG.Done()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
startWG.Done()
defer startWG.Done()

This should be after the be.send call, right? Maybe use defer instead? Or are you purposefully wanting to continue in the main goroutine before send is complete?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it should be before send. We need to ensure all the goroutines are started. The send is blocking

Copy link
Member

Choose a reason for hiding this comment

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

We need to ensure all the goroutines are started. The send is blocking

The goroutines will all be started regardless of where the startWG.Done() call is made, if I'm following correctly. The only impact is when the main goroutine will continue after the startWG.Wait() call. I'm wondering if it should wait until all sends are complete or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

the send operations cannot complete until they are unblocked, which we do after the shutdown - that's the purpose of the test case

Copy link
Member

Choose a reason for hiding this comment

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

Okay, thanks for clarifying 👍


// The exporter should have sent only one "merged" batch, in some cases it might send two if the shutdown
// happens before the batch is fully merged.
assert.LessOrEqual(t, uint64(1), sink.requestsCount.Load())
Copy link
Member

Choose a reason for hiding this comment

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

Is it valid to send two batches in some cases, as your comment is referencing? If so, should the assert here be 2 instead of 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's usually 1 or more in rare cases. LessOrEqual checks that the first argument is less or equal to the second one

@dmitryax dmitryax merged commit ff6f029 into open-telemetry:main May 30, 2024
49 checks passed
@github-actions github-actions bot added this to the next release milestone May 30, 2024
@dmitryax dmitryax deleted the fix-batcher-shutdown-deadlock branch May 30, 2024 17:58
@codeboten codeboten mentioned this pull request May 30, 2024
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.

[exporterhelper/batchsender] batchsender deadlock preventing shutdown
3 participants