Skip to content

Commit 73d929f

Browse files
committed
attack: document tricky critical section
Signed-off-by: Tomás Senart <tsenart@gmail.com>
1 parent 418ab07 commit 73d929f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/attack.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,16 @@ func (a *Attacker) hit(tr Targeter, atk *attack) *Result {
482482
err error
483483
)
484484

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

0 commit comments

Comments
 (0)