jackc / pgconn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Data race on onCancelWasCalled

bradfitz opened this issue · comments

I got an automated PR telling us to update from pgconn 1.10.0 to 1.10.1 which gave us a helpful diff link:

v1.10.0...v1.10.1

But it looks like the locking on onCancelWasCalled is wrong. The grouping on line 17 below the mutex on line 15 suggests that onCancelWasCalled is guarded by lock, but on line 50, it's assigned without holding the lock. (line 50 is in a goroutine, so the lock/defer Unlock on lines 35/36 don't affect it)

The grouping on line 17 is a bit confusing. The mutex guards the initialization of onCancelWasCalled on line 42. But the assignment on line 50 and the read on line 68 are synchronized by unwatchChan.

Perhaps I'm mistaken and there is a race, but I think the tests cover all the orders Watch, Unwatch, and context cancellation could occur and I can't get the race detector to fail.

Sorry, I should've been more explicit that I didn't actually see a data race. I never ran the code. I just read the diff and was suspicious.

Thanks for looking!