-
Notifications
You must be signed in to change notification settings - Fork 442
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
producer/consumer: clean up logging races #108
Conversation
Hi @judwhite thanks for finding this and the proposed fix. I'd prefer to use |
@mreiferson if we do that we should include logLvl for the (admittedly edge case) scenario where a partial write could be read from that address. we'll also have to accept that logger and logLvl may be out of sync for a brief moment if in the middle of a call to SetLogger and log is called - the uglier one is if NewConn is called and they're out of sync. this could also be solved by including the logger/logLvl in the sig of NewProducer, drop SetLogger and not add any locks/atomics - though it's a breaking API change, an annoyance to all for a theoretical issue. you could also do nothing and add a comment that SetLogger is expected to be called once during initialization. it keeps the code less complicated and documents assumptions. let me know your thoughts and I'll update. |
Ok, you've sold me on this approach. I've got a separate code comment 😁 |
@@ -201,7 +205,11 @@ func (w *Producer) sendCommandAsync(cmd *Command, doneChan chan *ProducerTransac | |||
|
|||
func (w *Producer) connect() error { | |||
w.guard.Lock() | |||
defer w.guard.Unlock() | |||
w.logGuard.RLock() |
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.
let's wrap logGuard
around a smaller critical section (without a defer) and store the w.logger
in a local var for passing it along into the new connection instantiation
Do we have the same race condition on |
@mreiferson what do you think about this approach? if you like it I'll do the same for |
even better, nice work 👍 |
@mreiferson ready for review |
cool LGTM mind squashing commits down? |
will do |
producer/consumer/conn: add getLogger to sync r/w access remove extra continue
producer/consumer: clean up logging races
producer: log method has potential for edge case race condition
(checking nil then using); logger/logLvl could be set anytime, added
Lock in SetLogger, RLock in log and connect methods
producer: remove unnecessary continue in transactionCleanup for select