Skip to content

fix: Make sure an alarm can't call onStop in the middle of a start() call#218

Merged
gabivlj merged 1 commit into
mainfrom
gv/on-exit-improvements
Jun 4, 2026
Merged

fix: Make sure an alarm can't call onStop in the middle of a start() call#218
gabivlj merged 1 commit into
mainfrom
gv/on-exit-improvements

Conversation

@gabivlj
Copy link
Copy Markdown
Collaborator

@gabivlj gabivlj commented Jun 4, 2026

We are also making sure onStop can't set 'stopped' if the method calls start().

@gabivlj gabivlj requested a review from a team as a code owner June 4, 2026 20:47
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 4, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/containers@218

commit: a5fd50a

Copy link
Copy Markdown

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm Bonk, and I've done a quick review of your PR.

The fix protects in-flight start() from racing with alarm()-triggered onStop by (a) deferring state.setRunning() until after container.start() and (b) only writing stopped in callOnStop if the cached state object reference hasn't been replaced. Logic looks correct. A few items to address:

  1. Missing changeset (high) - this is a user-facing behavior fix in Container.start() / callOnStop.
  2. Reference-equality invariant in setStoppedIfUnchanged is load-bearing and undocumented (medium) - silently breaks if ContainerState ever mutates this.status in place instead of reassigning.
  3. start() no longer sets state to running when the container is already running (low/medium) - subtle behavior change vs. previous code; worth confirming intentional.

Comment thread src/lib/container.ts
Comment thread src/lib/container.ts
Comment thread src/lib/container.ts
Comment thread src/tests/container.test.ts
Comment thread src/lib/container.ts
@ask-bonk
Copy link
Copy Markdown

ask-bonk Bot commented Jun 4, 2026

Review posted successfully on PR #218. Summary of feedback:

  1. Missing changeset - User-facing change in Container.start()/onStop semantics needs a .changeset/*.md per AGENTS.md.
  2. Undocumented reference-equality invariant in setStoppedIfUnchanged - relies on every state setter reassigning this.status; will silently break if anyone later refactors to in-place mutation. Suggested adding a doc comment.
  3. Subtle behavior change: start() no longer overwrites state to 'running' when the container is already running.
  4. Note on onStop throw path in callOnStop (informational, not a regression).
  5. Test gap: the alarm test does not actually exercise setStoppedIfUnchanged because state starts as 'stopped'; suggested mocking storage.get to 'running' so a future regression that drops the guard fails.

github run

@gabivlj gabivlj force-pushed the gv/on-exit-improvements branch from c63d3f8 to 94f4841 Compare June 4, 2026 20:51
@ask-bonk
Copy link
Copy Markdown

ask-bonk Bot commented Jun 4, 2026

LGTM

github run

call

We are also making sure onStop can't set 'stopped' if the method calls
start().
@gabivlj gabivlj force-pushed the gv/on-exit-improvements branch from 94f4841 to a5fd50a Compare June 4, 2026 20:53
@ask-bonk
Copy link
Copy Markdown

ask-bonk Bot commented Jun 4, 2026

I've already posted a thorough review on this PR (comments from ask-bonk covering changeset, reference-equality invariant, behavior change, throw path, and test gap). The author has responded and addressed/acknowledged my comments. There's nothing new to review.

LGTM

github run

@gabivlj gabivlj merged commit 84da034 into main Jun 4, 2026
10 checks passed
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.

2 participants