karlseguin / websocket.zig

A websocket implementation for zig
MIT License
302 stars 28 forks source link

Panic error when connecting from hostname #43

Closed mbaracz closed 2 months ago

mbaracz commented 2 months ago

Hello, in my project, I am using cross-site cookies when connecting to a WebSocket server. To make it work, I need to connect to the WebSocket server from the same domain where the cookies were set. Therefore, I am connecting to ws://localhost:port instead of ws://127.0.0.1:port.

There is a panic error when a user connects to the WebSocket via the hostname instead of the IP address:

thread 43109 panic: reached unreachable code
/snap/zig/12296/lib/std/debug.zig:401:14: 0x10a1fad in assert (websocket-zig-test)
    if (!ok) unreachable; // assertion failure
             ^
/home/mbaracz/.cache/zig/p/1220a36b9f1be391d474a22f7f52a3e8bd8027ac523d2db19c987328a03041ab1412/src/server/server.zig:1142:29: 0x1163a5e in inactive (websocket-zig-test)
            std.debug.assert(MANAGE_HS == false);
                            ^
/home/mbaracz/.cache/zig/p/1220a36b9f1be391d474a22f7f52a3e8bd8027ac523d2db19c987328a03041ab1412/src/server/server.zig:668:48: 0x1163922 in dataForHandshake (websocket-zig-test)
                self.base.conn_manager.inactive(hc);
                                               ^
/home/mbaracz/.cache/zig/p/1220a36b9f1be391d474a22f7f52a3e8bd8027ac523d2db19c987328a03041ab1412/src/server/server.zig:633:48: 0x113dd2f in dataAvailable (websocket-zig-test)
                success = self.dataForHandshake(hc) catch |err| blk: {
                                               ^
/home/mbaracz/.cache/zig/p/1220a36b9f1be391d474a22f7f52a3e8bd8027ac523d2db19c987328a03041ab1412/src/server/thread_pool.zig:183:17: 0x1120419 in worker (websocket-zig-test)
                @call(.auto, F, full_args);
                ^
/snap/zig/12296/lib/std/Thread.zig:409:13: 0x10eb432 in callFn__anon_10996 (websocket-zig-test)
            @call(.auto, f, args);
            ^
/snap/zig/12296/lib/std/Thread.zig:1297:30: 0x10b9337 in entryFn (websocket-zig-test)
                return callFn(f, self.fn_args);
                             ^
/snap/zig/12296/lib/std/os/linux/x86_64.zig:104:5: 0x10eb4c0 in clone (websocket-zig-test)
    asm volatile (
    ^
???:?:?: 0x0 in ??? (???)
run
└─ run websocket-zig-test failure

websocket.zig version: latest, master Zig version: 0.14.0-dev.1294+df6907f60

karlseguin commented 2 months ago

Uhh..that assertion is inverted. It's fixed now.