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

Issue with closing stream in Engine. #1

Closed
ciathefed opened this issue Nov 5, 2024 · 4 comments
Closed

Issue with closing stream in Engine. #1

ciathefed opened this issue Nov 5, 2024 · 4 comments

Comments

@ciathefed
Copy link

I have tried to use the example here and another one from the zinc-examples repo, and i keep getting this error.

thread 921703 panic: reached unreachable code
/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/posix.zig:245:22: 0x10446df9b in close (XXXXX)
            .BADF => unreachable, // Always a race condition.
                     ^
/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/net.zig:1798:32: 0x104490b53 in close (XXXXX)
            else => posix.close(s.handle),
                               ^
/Users/XXXXX/.cache/zig/p/122002abcd2597bc6c6dccaa76b6d871dcd461b4a82f4c80ff9fc68b01e402dae241/src/zinc/engine.zig:186:25: 0x1044c6c43 in worker (XXXXX)
            stream.close();
                        ^
/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/Thread.zig:429:13: 0x1044b4a87 in callFn__anon_11328 (XXXXX)
            @call(.auto, f, args) catch |err| {
            ^
/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/Thread.zig:674:30: 0x104491c9f in entryFn (XXXXX)
                return callFn(f, args_ptr.*);
                             ^
???:?:?: 0x19f3bf2e3 in ??? (libsystem_pthread.dylib)
???:?:?: 0x19f3ba0fb in ??? (libsystem_pthread.dylib)
  • Zig: 0.13.0
  • MacOS (aarch64)
@dravenk
Copy link
Member

dravenk commented Nov 6, 2024

Thanks for report. I'm working on the new IO handle and this error will be fixed by next release.

@dxps
Copy link

dxps commented Jan 30, 2025

Yesterday, using Zig 0.14.0-dev.2985, a minimal sample worked fine.

Today, using Zig 0.14.0-dev.2989, it fails (pretty identical with the one from the first message):

thread 3108413 panic: reached unreachable code
/home/dxps/apps/zig/lib/std/posix.zig:272:18: 0x122e1e3 in close (zinc_json_sample1)
        .BADF => unreachable, // Always a race condition.
                 ^
/home/dxps/apps/zig/lib/std/net.zig:1796:32: 0x125221a in close (zinc_json_sample1)
            else => posix.close(s.handle),
                               ^
/home/dxps/.cache/zig/p/1220a81e9421f9185fff79baba4beace2b8d9b4ec625ae3b0e06c3f3999993e87475/src/zinc/engine.zig:186:25: 0x1292e88 in worker (zinc_json_sample1)
            stream.close();
                        ^
/home/dxps/apps/zig/lib/std/Thread.zig:507:21: 0x126f148 in callFn__anon_17221 (zinc_json_sample1)
                    @call(.auto, f, args) catch |err| {
                    ^
/home/dxps/apps/zig/lib/std/Thread.zig:1378:30: 0x12537f1 in entryFn (zinc_json_sample1)
                return callFn(f, self.fn_args);
                             ^
/home/dxps/apps/zig/lib/std/os/linux/x86_64.zig:126:5: 0x126f231 in clone (zinc_json_sample1)
    asm volatile (
    ^
???:?:?: 0x0 in ??? (???)
Aborted

@dravenk Any ETA for the next release, please? Thanks.

@dxps
Copy link

dxps commented Jan 30, 2025

@dravenk Thanks for the quick feedback! 🙏

Of course, commenting out that stream.close() avoids the failure.
Now, I am wondering what are the side effects. Just ran a minimal test:

Image

After that, lots of connections (actually most of them, just a few of the - such as 3-4 - are in LISTEN and ESTAB) remained in CLOSE-WAIT state:

❯ ss -an | grep 8181 | wc -l
383
❯ 

I'll play and investigate further, to see how other Zig implementations are behaving in this case.

dxps added a commit to dxps/zig_playground that referenced this issue Jan 30, 2025
@dravenk
Copy link
Member

dravenk commented Jan 31, 2025

Thank you all. This is the fix I remember, but the side effects are pretty obvious. Since std.net.server is very slow, the new branch will remove the std.net.server dependency, which will have a lot of work to do. This temporary code will also be removed. Anyway, thank you very much for your support and I will release the new version as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants