-
Notifications
You must be signed in to change notification settings - Fork 116
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
fix: Non-empty error channel will not block writes #324
Conversation
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
ad6374b
to
125406a
Compare
125406a
to
d99575f
Compare
Closes #318
Proposed Changes
Make sure the non-read error channel will not block write or closing.
Checklist