Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: WebSocket without Durable Object stays in CLOSING state after close #2569

Open
RaresAil opened this issue Jun 3, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@RaresAil
Copy link

RaresAil commented Jun 3, 2024

Which Cloudflare product(s) does this pertain to?

Workers Runtime

What version(s) of the tool(s) are you using?

3.58.0 [Wranger]

What version of Node are you using?

22.2

What operating system and version are you using?

macOS Sonoma 14.5

Describe the Bug

Observed behavior

When closing the connection from the client, the server stays in COLOSING for more than 40s

Expected behavior

To change the state to CLOSED

Steps to reproduce

Please provide the following:

Follow the steps for the server here: https://developers.cloudflare.com/workers/examples/websockets/ and run it from postman, and on the close event watch for the readyState which stays on CLOSING for more than 40s and the postman is on Disconneting for 30s and after an error is thrown with No closing frame

Example code:

const upgradeHeader = c.req.header('Upgrade');
    if (!upgradeHeader || upgradeHeader !== 'websocket') {
      return new Response('Expected Upgrade: websocket', { status: 426 });
    }

    const webSocketPair = new WebSocketPair();
    const client = webSocketPair[0];
    const server = webSocketPair[1];

    server.accept();

    server.addEventListener(
      'close',
      (e) => {
        console.log('close', e, server.readyState);
        setTimeout(() => console.log(server.readyState), 5000);
      },
      {
        once: true
      }
    );

    server.addEventListener(
      'error',
      (e) => {
        console.log('error', e, server.readyState);
      },
      {
        once: true
      }
    );

    server.addEventListener('message', (e) => {
      console.log(e);
    });

    return new Response(null, {
      status: 101,
      webSocket: client
    });
    ```


### Workaround

To call again .close in the close event handler and suppress the connection lost error


### Please provide a link to a minimal reproduction

_No response_

### Please provide any relevant error logs

Error from postman after 30s: 1006 Abnormal Closure: No close frame was received.
@RaresAil RaresAil added the bug Something isn't working label Jun 3, 2024
@penalosa penalosa transferred this issue from cloudflare/workers-sdk Aug 21, 2024
@penalosa penalosa removed this from workers-sdk Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant