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: Non-empty error channel will not block writes #324

Merged
merged 1 commit into from
May 18, 2022

Conversation

vlastahajek
Copy link
Contributor

Closes #318

Proposed Changes

Make sure the non-read error channel will not block write or closing.

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are in semantic format

@vlastahajek vlastahajek requested a review from sranka May 10, 2022 08:36
@vlastahajek vlastahajek marked this pull request as draft May 10, 2022 09:06
api/write.go Outdated
@@ -103,7 +103,7 @@ func (w *WriteAPIImpl) SetWriteFailedCallback(cb WriteFailedCallback) {
// The chan is unbuffered and must be drained or the writer will block.
func (w *WriteAPIImpl) Errors() <-chan error {
if w.errCh == nil {
w.errCh = make(chan error)
w.errCh = make(chan error, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please adjust the documentation to match the implementation, the channel is now buffered and contains the last error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

api/write.go Outdated
Comment on lines 182 to 190
go func(err error) {
if err != nil && w.errCh != nil {
if len(w.errCh) == 0 {
w.errCh <- err
} else {
log.Warn("Cannot write error to error channel, it is not read")
}
}
}(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This kind of non-blocking write is suspicious to me (at least not idiomatic). Couldn't you simply:

if err != nil && w.errCh != nil {
  select {
    case w.errCh <- err:
        // err consumed by err channel
    default:
        log.Warn("Cannot write error to error channel, it is full", err)
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@vlastahajek vlastahajek force-pushed the fix/write_flush_closing branch 2 times, most recently from ad6374b to 125406a Compare May 17, 2022 13:25
@vlastahajek vlastahajek marked this pull request as ready for review May 17, 2022 13:25
@vlastahajek vlastahajek force-pushed the fix/write_flush_closing branch from 125406a to d99575f Compare May 18, 2022 12:27
@vlastahajek vlastahajek merged commit 841a340 into influxdata:master May 18, 2022
@vlastahajek vlastahajek deleted the fix/write_flush_closing branch May 18, 2022 13:43
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.

Client.Close() blocked by write API Flush() (if (?) it can't send metrics)
2 participants