You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sync: records made with context.WithoutCancel still fail when the session's context ends #208
Several places record a sync answer in a transaction started with context.WithoutCancel(ctx), so the record survives the end of a session. Each closure then passes the cancellablectx to the statements inside it:
internal/syncer/loop.go:686-694 and :699-710: tx.AnswerPush(ctx, …), tx.DeleteAgreed(ctx, …), tx.PutAgreed(ctx, …)
internal/syncer/loop.go:746 and :814: l.agree(in)(ctx, tx, …)
internal/syncer/loop.go:796-798: tx.AnswerPush(ctx, …) in refuseHere
internal/syncer/loop.go:879-881 and :993-995: tx.DeleteApplying(ctx, …)
internal/hub/log.go:191 and :288: tx.RecordPush(ctx, a), the hub's record of the answer it gave a push
internal/vault/apply.go:110: rec(ctx, tx, f) in recordOnly
database/sql checks the context of each statement in a transaction ((*Tx).grabConn returns ctx.Err() when that context is done). So once the session's context is cancelled, the first statement fails, DB.Tx rolls back, and the record is lost: the transaction's own context is never the one that counts.
Why it matters: at internal/hub/log.go:288, v.Push has already changed the hub's vault when RecordPush runs. If the device disconnects at that moment, the hub keeps the change but not the answer, so the device's repeat of the push is not seen as a repeat (answered, log.go:243). On the device side, an answer the hub gave can be lost in the same way, and the push is sent again.
What's wanted: pass the context the transaction was started with into each closure (for example bg := context.WithoutCancel(ctx) and use bg for the Tx and its statements). A test can cancel the context between the vault change and the record and check that the record is there (the Crash hooks in internal/hub and internal/syncer give a place to do it).
Activity