Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-not-listening-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/containers": patch
---

Fix NOT_LISTENING_ERROR constant to match local-dev runtime error message
2 changes: 1 addition & 1 deletion src/lib/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const NO_CONTAINER_INSTANCE_ERROR =
const RATE_LIMITED_ERROR = 'you are requesting too many containers per second';
const RUNTIME_SIGNALLED_ERROR = 'runtime signalled the container to exit:';
const UNEXPECTED_EXIT_ERROR = 'container exited with unexpected exit code:';
const NOT_LISTENING_ERROR = 'the container is not listening';
const NOT_LISTENING_ERROR = 'container is not listening';
const CONTAINER_STATE_KEY = '__CF_CONTAINER_STATE';
const OUTBOUND_CONFIGURATION_KEY = 'OUTBOUND_CONFIGURATION';

Expand Down
25 changes: 25 additions & 0 deletions src/tests/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,31 @@ describe('Container', () => {
expect(mockCtx.container.getTcpPort).toHaveBeenCalledWith(8080);
});

test('startAndWaitForPorts should recognise local-dev "not listening" error without leading "the"', async ({
mockCtx,
container,
}) => {
// In local dev (wrangler dev) the runtime returns "container is not listening"
// without the leading "the" that production uses. Both variants must be
// recognised so doStartContainer treats the state as benign and returns
// instead of retrying until timeout.
const localDevError = new Error('container is not listening on TCP address 10.0.0.1:8080');
const fetchMock = vi
.fn()
.mockRejectedValueOnce(localDevError)
.mockResolvedValue(new Response('ok'));
mockCtx.container.getTcpPort.mockReturnValue({ fetch: fetchMock });

await container.startAndWaitForPorts(8080);

expect(mockCtx.container.getTcpPort).toHaveBeenCalledWith(8080);
// Exactly 2 calls: doStartContainer recognises the error and returns
// immediately (1 call), then waitForPort succeeds on its first attempt
// (1 call). Without the fix the error is not recognised, doStartContainer
// retries, and the count rises to 3+.
expect(fetchMock).toHaveBeenCalledTimes(2);
});

test('startAndWaitForPorts should surface rate-limited startup errors on the final retry', async ({
mockCtx,
container,
Expand Down