Skip to content

Fix race condition with sending a request while container is stopping#148

Draft
rushilmehra wants to merge 1 commit intomainfrom
rm/container-shutdown-race
Draft

Fix race condition with sending a request while container is stopping#148
rushilmehra wants to merge 1 commit intomainfrom
rm/container-shutdown-race

Conversation

@rushilmehra
Copy link

Due to some quirks in the runtime, it's possible for the DO to send a request to a container when it thinks the container is in a running state, but while the request is in flight, the container stops and the monitor promise resolves. This results in an error, and instead of retrying we throw a 500 error. Instead, recognize this case and restart the container.

This is a bandage solution, but we will follow up with some improvements to the runtime that will clean up the state management required in this DO class.

@rushilmehra rushilmehra requested a review from a team as a code owner February 2, 2026 16:45
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 2, 2026

Open in StackBlitz

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

commit: 5fd978a

@rushilmehra rushilmehra force-pushed the rm/container-shutdown-race branch from bde0a0a to db3042c Compare February 26, 2026 18:04
@rushilmehra rushilmehra marked this pull request as draft February 26, 2026 18:56
@rushilmehra rushilmehra force-pushed the rm/container-shutdown-race branch 2 times, most recently from f3ee562 to abc450c Compare February 26, 2026 19:02
Due to some quirks in the runtime, it's possible for the DO to send a
request to a container when it thinks the container is in a running
state, but while the request is in flight, the container stops and the
monitor promise resolves. This results in an error, and instead of
retrying we throw a 500 error. Instead, recognize this case and restart
the container.

This is a bandage solution, but we will follow up with some improvements
to the runtime that will clean up the state management required in this
DO class.
@rushilmehra rushilmehra force-pushed the rm/container-shutdown-race branch from abc450c to 5fd978a Compare February 26, 2026 19:10
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