karlseguin / http.zig

An HTTP/1.1 server for zig
MIT License
454 stars 31 forks source link

Calling `server.stop()` crashes the whole process #37

Closed iacore closed 5 months ago

iacore commented 5 months ago

How to reproduce (roughly)

How to reproduce this issue exactly. It's not 100% reproducible, and I don't know why.

git clone https://codeberg.org/iacore/xn--8st83p --branch httpz-bug && cd httpz-bug
zig version # use 0.11.0
zig build run

# then, open the localhost:xxxx url shown in terminal in your browser

# now press Ctrl+C to stop the process

# now you should see the following error trace 

error trace

/home/user/.zvm/0.11.0/lib/std/heap/arena_allocator.zig:46:40: 0x2c4c1f in deinit (www.status)
        var it = self.state.buffer_list.first;
                                       ^
/home/user/.cache/zig/p/1220d042f0fe4b04840e27ecef3ab770444c4ac65dd043f514b37c6cc615c317bf3f/src/worker.zig:433:26: 0x2aaa04 in deinit (www.status)
        self.arena.deinit();
                         ^
/home/user/.cache/zig/p/1220d042f0fe4b04840e27ecef3ab770444c4ac65dd043f514b37c6cc615c317bf3f/src/worker.zig:688:24: 0x3082f9 in deinit (www.status)
            conn.deinit(allocator);
                       ^
/home/user/.cache/zig/p/1220d042f0fe4b04840e27ecef3ab770444c4ac65dd043f514b37c6cc615c317bf3f/src/worker.zig:548:25: 0x2c574d in deinit (www.status)
        conn_pool.deinit();
                        ^
/home/user/.cache/zig/p/1220d042f0fe4b04840e27ecef3ab770444c4ac65dd043f514b37c6cc615c317bf3f/src/worker.zig:75:32: 0x2adb70 in deinit (www.status)
            self.manager.deinit();
                               ^
/home/user/.cache/zig/p/1220d042f0fe4b04840e27ecef3ab770444c4ac65dd043f514b37c6cc615c317bf3f/src/httpz.zig:300:38: 0x2ac99c in listen (www.status)
                    workers[i].deinit();
                                     ^
/home/user/computing/philosophy/quadstore/src/main.zig:166:22: 0x2af1a6 in main (www.status)
    try server.listen();
                     ^
/home/user/.zvm/0.11.0/lib/std/start.zig:574:37: 0x2b1cde in main (www.status)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x73d2c39afccf in ??? (libc.so.6)
Unwind information for `libc.so.6:0x73d2c39afccf` was not available, trace may be incomplete
karlseguin commented 5 months ago

I believe this is fixed in the zig-0.11 branch. And the same fix has been applied to the nonblocking_threadpool branch which I'm currently testing and should be merging into master next week.

The issue is a double-free of the connection by the connect manager and the connection pool.

iacore commented 5 months ago

I think the issue is fixed now. Thanks!