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: add concurrency panic protection around Client and WriteAPIImpl Close #319

Merged
merged 1 commit into from
Mar 31, 2022

Conversation

dleonard203
Copy link
Contributor

@dleonard203 dleonard203 commented Mar 26, 2022

Proposed Changes

This PR aims to address #317 . If multiple goroutines call influxdb2.Client.Close(), or api.WriteAPI.Close(), it is possible for there to be a panic due to closing a closed channel.

Closes #317

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are in semantic format
  • Sign CLA (if not already signed)

@dleonard203 dleonard203 changed the title Update: add concurrency panic protection around WriteAPIImpl.Close Fix: add concurrency panic protection around Client and WriteAPIImpl Close Mar 26, 2022
@@ -194,6 +197,8 @@ x:
// Close finishes outstanding write operations,
// stop background routines and closes all channels
func (w *WriteAPIImpl) Close() {
w.closingMu.Lock()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is an exported type, users could (and may already) call WriteAPIImpl{} without instantiating this new mutex, so it could default to nil. Does doing a nil check make sense here before acquiring the lock?

Copy link
Contributor

Choose a reason for hiding this comment

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

As there is no nil check for other fields, it is not necessary.

@vlastahajek vlastahajek changed the title Fix: add concurrency panic protection around Client and WriteAPIImpl Close fix: add concurrency panic protection around Client and WriteAPIImpl Close Mar 31, 2022
Copy link
Contributor

@vlastahajek vlastahajek left a comment

Choose a reason for hiding this comment

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

Thanks for the issue and the fix!

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.

Panic: close on closed channel when multiple goroutines call influxdb2.Client.Close()
2 participants