ikskuh / zig-network

A smallest-common-subset of socket functions for crossplatform networking, TCP & UDP
MIT License
452 stars 55 forks source link

Darwin: connection-mode socket was connected already #69

Open kassane opened 1 year ago

kassane commented 1 year ago

Uses zig-macos-x86_64-0.11.0-dev.3950+a75531073 same source https://github.com/MasterQ32/zig-network/commit/7b5f76ea09626b96755c027bf4bd5b7e45297027 (standalone project test)

edit: repo fork (CI test): https://github.com/kassane/zig-network/actions/runs/5568702251

Build ok. however when running:

thread 7538 panic: reached unreachable code
/Users/runner/hostedtoolcache/zig/master/x64/lib/std/os.zig:5985:24: 0x10d5fe61b in sendto (ntp-zig)
            .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified
                       ^
/Users/runner/.cache/zig/p/122090e7cb4459c2224399a45c56f47462733b919aa547c96b8c14ee705bfa22976e/network.zig:520:46: 0x10d5ee39f in sendTo (ntp-zig)
            .ipv4 => |sockaddr| try sendto_fn(self.internal, data, flags, @ptrCast(&sockaddr), @sizeOf(@TypeOf(sockaddr))),
                                             ^
/Users/runner/.cache/zig/p/122090e7cb4459c2224399a45c56f47462733b919aa547c96b8c14ee705bfa22976e/network.zig:469:35: 0x10d5d5859 in send (ntp-zig)
            return try self.sendTo(ep, data);
                                  ^
/Users/runner/hostedtoolcache/zig/master/x64/lib/std/io/writer.zig:17:27: 0x10d5ac956 in write (ntp-zig)
            return writeFn(self.context, bytes);
                          ^
/Users/runner/hostedtoolcache/zig/master/x64/lib/std/io/writer.zig:23:40: 0x10d5a8774 in writeAll (ntp-zig)
                index += try self.write(bytes[index..]);
                                       ^
/Users/runner/work/ntp-zig/ntp-zig/src/main.zig:14:31: 0x10d5a7f01 in main (ntp-zig)
    try sock.writer().writeAll(&request);
                              ^
/Users/runner/hostedtoolcache/zig/master/x64/lib/std/start.zig:608:37: 0x10d5a8fb2 in main (ntp-zig)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x115a8652d in ??? (???)
???:?:?: 0x0 in ??? (???)
run ntp-zig: error: the following command terminated unexpectedly:
/Users/runner/work/ntp-zig/ntp-zig/zig-cache/o/703913aea06a991a2c9b3f3ffe120bda/ntp-zig 
Build Summary: 1/3 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
+- run ntp-zig failure
error: the following build command failed with exit code 1:
/Users/runner/work/ntp-zig/ntp-zig/zig-cache/o/b553499fe5c39aecb53f8ff1ef25817f/build /Users/runner/hostedtoolcache/zig/master/x64/zig /Users/runner/work/ntp-zig/ntp-zig /Users/runner/work/ntp-zig/ntp-zig/zig-cache /Users/runner/.cache/zig run -freference-trace -freference-trace
twystd commented 1 month ago

Was just about to file an issue for this - example attached in case it's of any use to you. The actual bug is on lines 669-670:

        if (self.endpoint) |ep|
            return try self.sendTo(ep, data);

A connected socket already has an endpoint so you can just use send - the attached example works if you comment out lines 669 and 670.

udp_connect.zig.zip