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

WebSocketStream unhandled rejection #25077

Closed
sergeysolovev opened this issue Aug 17, 2024 · 3 comments · Fixed by #25125
Closed

WebSocketStream unhandled rejection #25077

sergeysolovev opened this issue Aug 17, 2024 · 3 comments · Fixed by #25125
Labels
bug Something isn't working correctly ext/websocket related to the ext/websocket crate

Comments

@sergeysolovev
Copy link

Version: Deno 1.45.5
OS: Linux

Steps: start a server which accepts a ws connection, not necessary to send anything from the server. Can use this one from another issue I’ve filed, just please comment out the part where it sends tons of messages. Start the client script (below). Exit the server script, in my case the client gets Unexpected EOF error.

Somehow I get unhandled rejection, though in the client code below I can’t see where it pops up from. Is possible it gets thrown and not intercepted somewhere internally?

const wss = new WebSocketStream('ws://localhost:3333/');
const conn = await wss.opened;
const reader = conn.readable.getReader();

addEventListener('unhandledrejection', (event) => {
  event.preventDefault();
  console.log('unhandledrejection', event);
});

wss.closed.then((x) => {
  console.log('closed', x);
}).catch((err) => {
  console.log('err', err);
});

while (true) {
  try {
    const { value, done } = await reader.read();
    if (done) {
      console.log('done');
      break;
    }
    console.log('msg', value);
  } catch (error) {
    console.log('read_loop_error', error);
    break;
  }
}
@sergeysolovev
Copy link
Author

The client script output looks like this to me:

$ deno run -A wss_repro.ts
read_loop_error WebSocketError {
  message: "Unexpected EOF",
  name: "WebSocketError",
  closeCode: null,
  reason: ""
}
err WebSocketError {
  message: "Unexpected EOF",
  name: "WebSocketError",
  closeCode: null,
  reason: ""
}
unhandledrejection PromiseRejectionEvent {
  bubbles: false,
  cancelable: true,
  composed: false,
  currentTarget: Window {},
  defaultPrevented: true,
  eventPhase: 2,
  srcElement: null,
  target: Window {},
  returnValue: false,
  timeStamp: 0,
  type: "unhandledrejection",
  promise: Promise {
    <rejected> WebSocketError {
      message: "Unexpected EOF",
      name: "WebSocketError",
      closeCode: null,
      reason: ""
    }
  },
  reason: WebSocketError {
    message: "Unexpected EOF",
    name: "WebSocketError",
    closeCode: null,
    reason: ""
  }
}

@sergeysolovev
Copy link
Author

Just in case: to get Unexpected EOF I exit the server process without closing the connection on the server side

@littledivy littledivy added bug Something isn't working correctly ext/websocket related to the ext/websocket crate labels Aug 17, 2024
@sergeysolovev
Copy link
Author

Seems to be related #22165, but the fix mentioned there doesn’t work in my case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly ext/websocket related to the ext/websocket crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants