-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent: harden dispatcher concurrency (#484)
* make nextTransactionID an atomic variable This commit has 2 main benefits: 1) It makes it impossible to access nextTransactionID un-atomically 2) It fixes a small bug where we would have racy (albeit atomic) accesses to nextTransactionID. Consider the following interleaving: Dispactcher Call #1 and #2: Read nextTransactioID Dispactcher Call #1 and #2: Bump nextTransactionId *locally* and then write it back. The same value is written back twice. Dispactcher Call #1 and #2: Send a message with the newly minted transaction ID, x. Note, *two* messages are sent with x! So two responses will come back. First response arrives: Entry is deleted from dispatcher's waited hash map. Second response arrives: Received message with id x, but no record of it, because the entry was deleted when the first message arrived. The solution is just to use an atomic read-modify-write operation in the form of .Add(1) * protect disp.waiters with mutex disp.Call can be called from multiple threads (the main disp.run() thread, and the healthchecker thread), so access needs to be guarded with a mutex as the underlying map is not thread safe. * rename nextTransactionID to lastTransactionID
- Loading branch information
Showing
2 changed files
with
26 additions
and
13 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