Skip to content

Commit

Permalink
attack: document tricky critical section
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Senart <[email protected]>
  • Loading branch information
tsenart committed Jul 19, 2023
1 parent 418ab07 commit 73d929f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,16 @@ func (a *Attacker) hit(tr Targeter, atk *attack) *Result {
err error
)

//
// Subtleness ahead! We need to compute the result timestamp in
// the same critical section that protects the increment of the sequence
// number because we want the same total ordering of timestamps and sequence
// numbers. That is, we wouldn't want two results A and B where A.seq > B.seq
// but A.timestamp < B.timestamp.
//
// Additionally, we calculate the result timestamp based on the same beginning
// timestamp using the Add method, which will use monotonic time calculations.
//
atk.seqmu.Lock()
res.Timestamp = atk.began.Add(time.Since(atk.began))
res.Seq = atk.seq
Expand Down

0 comments on commit 73d929f

Please sign in to comment.