Skip to content

Commit

Permalink
finagle-mux: unmap promise from tagMap to avoid races
Browse files Browse the repository at this point in the history
Problem

There is a race where promises in mux dispatcher can be
updated twice.

Solution

`unmap` the `promise` from `TagMap` before setting a
value to the `promise`. `TagMap`'s synchronized operations
gaurantee a `promise` won't be fetched twice, thus be set
a value twice.

RB_ID=712013
  • Loading branch information
blackicewei authored and jenkins committed Jul 13, 2015
1 parent e2f4187 commit a10d17e
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,13 @@ private[twitter] class ClientDispatcher (
loop() onFailure { case exc =>
trans.close()
val result = Throw(exc)
for ((tag, p) <- reqs)
p() = result
for (tag <- tags) {
/*
* unmap the `tag` here to prevent the associated promise from
* being fetched from the tag map again, and setting a value twice.
*/
for (p <- reqs.unmap(tag)) p() = result
}
}

def ping(): Future[Unit] = {
Expand Down

0 comments on commit a10d17e

Please sign in to comment.