Skip to content

fix(substore): prevent timed-out requests from persisting writes - #45

Open
takomitkm wants to merge 2 commits into
SaintWe:multi-tenantfrom
takomitkm:fix/timeout-cancellation
Open

takomitkm wants to merge 2 commits into
SaintWe:multi-tenantfrom
takomitkm:fix/timeout-cancellation

Conversation

@takomitkm

Copy link
Copy Markdown

Summary

The timeout handler only cleared done and returned 504. initSubStore
kept running and could still write user data after the caller gave up.

The request context now has an aborted flag and cancel(). On timeout
(HTTP and cron), cancel() marks the context and detaches done; $done
ignores cancelled contexts and flushSubStoreRequestContext refuses to
persist late writes. $notification.post is also gated on aborted, so a
timed-out script can no longer trigger Telegram/Bark/etc. notifications.

JavaScript cannot forcibly kill a script already handed to the global
dispatch. This fix gates all side-effect exits so work that continues after
timeout cannot produce a persisted or notified effect.

Tests

  • Cancel semantics, the flush gate, and a normal (uncancelled) flush.
  • New: a notification-gate test that fires before and after cancellation.
  • The full-504 regression now triggers the "late" write only after the
    504 response. Previously it wrote at 10 ms with a 50 ms timeout, i.e.
    before cancellation, so it did not actually prove the fix.

The Workers CI job now runs these Node tests.

Part of the split from the original combined PR.

The timeout handler only cleared done and returned 504; initSubStore kept
running and could still write user data after the caller had given up.

Add an aborted flag and cancel() to the request context. On timeout (HTTP
and cron), cancel() marks the context and detaches done;  ignores
cancelled contexts and flushSubStoreRequestContext refuses to persist late
writes. The HTTP timeout is now injectable for tests (default unchanged).

Add regression tests covering cancel semantics, the flush gate, and a full
504 path where a late script write must not be persisted.
Fix the full-504 regression test: previously the 'late' write happened at
10ms with a 50ms timeout (i.e. before cancellation). Now the write is
triggered only after the 504 response, proving it is genuinely late.

Gate .post on ctx.aborted so timed-out scripts cannot send
Telegram/Bark/etc. Include the shared test hooks loader and wire the suite
into CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant