oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.6k stars 2.72k forks source link

ServerWebSocket.close() throws error #1388

Closed ElYaiko closed 8 months ago

ElYaiko commented 1 year ago

What version of Bun is running?

0.2.1

What platform is your computer?

Darwin 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:35 PDT 2022;

What steps can reproduce the bug?

I'm testing a simple websocket server with bun as the doc says:

index.mjs

const server = Bun.serve({
  port: 8282,
  websocket: {
    open: ws => {
      console.log('open')
      setTimeout(() => {
        console.log('close')
        ws.close()
      }, 2000)
    },
    message: (ws, msg) => {
      console.log('msg', msg)
    },
    close: ws => {
      console.log('closed')
    }
  },
  fetch(req, sv){
    if(sv.upgrade(req)) return;

    return new Response('http req');
  }
})

console.log(`Server running at ${server.hostname}:${server.port}`)

Server starts normal and connects normal but when trying to use ws.close() in open()throws an error

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

I'm trying to close the connection after is connected.

What do you see instead?

I get:

SegmentationFault at 0x3000000000000000

----- bun meta -----
Bun v0.2.1 (1835e4b9) macOS Silicon 21.6.0
RunCommand: 
Elapsed: 6866ms | User: 14ms | Sys: 32ms
RSS: 17.65MB | Peak: 20.30MB | Commit: 67.11MB | Faults: 810
----- bun meta -----

Ask for #help in https://bun.sh/discord or go to https://bun.sh/issues

Additional information

No response

Jarred-Sumner commented 1 year ago

Stack trace:

0   bun-debug                              0x1043f5584 SSL_get_shutdown + 0
1   bun-debug                              0x1071f4b40 us_socket_write + 80
2   bun-debug                              0x1056d0930 uWS::AsyncSocket<true>::write(char const*, int, bool, int) + 356 (AsyncSocket.h:289)
3   bun-debug                              0x1056d0aa4 uWS::AsyncSocket<true>::uncork(char const*, int, bool) + 128 (AsyncSocket.h:328)
4   bun-debug                              0x10720a048 uWS::WebSocket<true, true, void*>::send(std::__1::basic_string_view<char, std::__1::char_traits<char> >, uWS::OpCode, bool, bool) + 572
5   bun-debug                              0x107209d48 uWS::WebSocket<true, true, void*>::end(int, std::__1::basic_string_view<char, std::__1::char_traits<char> >) + 188
6   bun-debug                              0x106cc63a0 .uws.AnyWebSocket.end + 192 (uws.zig:701)
7   bun-debug                              0x1070ed764 ServerWebSocketPrototype__close + 1316 (server.zig:3407)
8   bun-debug                              0x1056a2f90 WebCore::ServerWebSocketPrototype__closeCallback(JSC::JSGlobalObject*, JSC::CallFrame*) + 104 (ZigGeneratedClasses.cpp:4006)
ElYaiko commented 1 year ago

Any update?, still not working in 0.2.2 neither

zhiyuang commented 1 year ago

Stack trace:

0   bun-debug                                0x1043f5584 SSL_get_shutdown + 0
1   bun-debug                                0x1071f4b40 us_socket_write + 80
2   bun-debug                                0x1056d0930 uWS::AsyncSocket<true>::write(char const*, int, bool, int) + 356 (AsyncSocket.h:289)
3   bun-debug                                0x1056d0aa4 uWS::AsyncSocket<true>::uncork(char const*, int, bool) + 128 (AsyncSocket.h:328)
4   bun-debug                                0x10720a048 uWS::WebSocket<true, true, void*>::send(std::__1::basic_string_view<char, std::__1::char_traits<char> >, uWS::OpCode, bool, bool) + 572
5   bun-debug                                0x107209d48 uWS::WebSocket<true, true, void*>::end(int, std::__1::basic_string_view<char, std::__1::char_traits<char> >) + 188
6   bun-debug                                0x106cc63a0 .uws.AnyWebSocket.end + 192 (uws.zig:701)
7   bun-debug                                0x1070ed764 ServerWebSocketPrototype__close + 1316 (server.zig:3407)
8   bun-debug                                0x1056a2f90 WebCore::ServerWebSocketPrototype__closeCallback(JSC::JSGlobalObject*, JSC::CallFrame*) + 104 (ZigGeneratedClasses.cpp:4006)

@Jarred-Sumner hi jarred, curious how you did print the stack trace like this?

Electroid commented 8 months ago

This crash no longer occurs as of Bun v1.0.26.