instantout: use fresh contexts for cleanup

Cleanup contexts were derived from caller contexts that may be canceled.

Use independent timeout contexts for reservation unlocks and server cancel.
This commit is contained in:
Slyghtning 2026-05-20 21:48:44 +02:00
parent 6b3f4d9856
commit db18e6e1d2

View file

@ -632,13 +632,15 @@ func (f *FSM) handleErrorAndUnlockReservations(ctx context.Context,
err error) fsm.EventType {
// We might get here from a canceled context, we create a new context
// with a timeout to unlock the reservations.
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
unlockCtx, cancel := context.WithTimeout(
context.Background(), time.Second*30,
)
defer cancel()
// Unlock the reservations.
for _, reservation := range f.InstantOut.Reservations {
err := f.cfg.ReservationManager.UnlockReservation(
ctx, reservation.ID,
unlockCtx, reservation.ID,
)
if err != nil {
f.Errorf("error unlocking reservation: %v", err)
@ -650,7 +652,9 @@ func (f *FSM) handleErrorAndUnlockReservations(ctx context.Context,
// release the reservations. This can be done in a goroutine as we
// wan't to fail the fsm early.
go func() {
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
ctx, cancel := context.WithTimeout(
context.Background(), time.Second*30,
)
defer cancel()
_, cancelErr := f.cfg.InstantOutClient.CancelInstantSwap(
ctx, &swapserverrpc.CancelInstantSwapRequest{