-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with context being cancelled prematurely (#70)
There was a bug where we would cancel the health-checker's context after warming up the connection, which means that health checkers that rely on the context would start permanently failing after the first check. To reproduce, I updated the `FakeHealthChecker` used in tests to be context-sensitive: it uses `context.AfterFunc` to permanently mark a connection as unhealthy if/when the context is cancelled. One of my local test runs then hung, revealing a potential deadlock bug. The issue was that the balancer would acquire a lock and then call `check.Close()`. For the `FakeHealthChecker`, closing then acquires the health checker's lock. But over in the `FakeHealthChecker.UpdateHealthState`, we acquire locks in the reverse order: acquiring the health checker's lock and then calling `tracker.UpdateHealthState` (which ends up calling into the balancer and acquiring the balancer's lock). Having the lock acquisition order differ exposes a potential deadlock. The deadlock is also fixed in this branch, by making it so that we don't ever try to acquire both locks at the same time, much less acquire them in different orders.
- Loading branch information
Showing
2 changed files
with
36 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters