AddressInUse #NV3 on Zig

I’m stuck on Stage #NV3 using Zig

The test pass for the stage but then fail for #VI6 because AddressInUse
The socket close is there:

const client_fd = try posix.accept(sock_fd, &client_addr, &client_addr_len, posix.SOCK.CLOEXEC); defer posix.close(client_fd);

I was wondering if I’m doing something wrong or is a problem of the test runner?

Here are my logs:

include relevant logs here (please make sure to keep the backticks around this!)

And here’s a snippet of my code:

Debug = true

[tester::#NV3] Running tests for Stage #NV3 (Send Correlation ID)
[tester::#NV3] $ ./your_program.sh /tmp/server.properties
[tester::#NV3] Connecting to broker at: localhost:9092
[tester::#NV3] Connection to broker at localhost:9092 successful
[tester::#NV3] Sending "ApiVersions" (version: 4) request (Correlation id: 7)
[tester::#NV3] Hexdump of sent "ApiVersions" request:
[tester::#NV3] Idx  | Hex                                             | ASCII
[tester::#NV3] -----+-------------------------------------------------+-----------------
[tester::#NV3] 0000 | 00 00 00 23 00 12 00 04 00 00 00 07 00 09 6b 61 | ...#..........ka
[tester::#NV3] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli..kafka-c
[tester::#NV3] 0020 | 6c 69 04 30 2e 31 00                            | li.0.1.
[tester::#NV3]
[tester::#NV3] Hexdump of received "ApiVersions" response:
[tester::#NV3] Idx  | Hex                                             | ASCII
[tester::#NV3] -----+-------------------------------------------------+-----------------
[tester::#NV3] 0000 | 00 00 00 00 00 00 00 07                         | ........
[tester::#NV3]
[tester::#NV3] [Decoder] - .Response
[tester::#NV3] [Decoder]   - .message_length (0)
[tester::#NV3] [Decoder] - .ResponseHeader
[tester::#NV3] [Decoder]   - .correlation_id (7)
[tester::#NV3] ✓ Correlation ID: 7
[tester::#NV3] Test passed.
[tester::#NV3] Terminating program
[tester::#NV3] Program terminated successfully

[tester::#VI6] Running tests for Stage #VI6 (Bind to a port)
[tester::#VI6] $ ./your_program.sh /tmp/server.properties
[tester::#VI6] Connecting to port 9092...
[your_program] error: AddressInUse
[your_program] /usr/local/zig/lib/std/posix.zig:3739:27: 0x10df4e1 in bind (main)
[your_program]             .ADDRINUSE => return error.AddressInUse,
[your_program]                           ^
[your_program] /app/src/main.zig:14:5: 0x10decc4 in main (main)
[your_program]     try posix.bind(sock_fd, &addr.any, addr.getOsSockLen());
[your_program]     ^
[tester::#VI6] Looks like your program has terminated. A kafka server is expected to be a long-running process.
[tester::#VI6] Test failed
[tester::#VI6] Terminating program
[tester::#VI6] Program terminated successfully

To fix this I had to add the socket option to be able to reuse it .. maybe needs to be added to the boilerplate?

    // Set SO_REUSEADDR to allow immediate port reuse
    const reuse_addr: c_int = 1;
    try posix.setsockopt(sock_fd, posix.SOL.SOCKET, posix.SO.REUSEADDR, std.mem.asBytes(&reuse_addr));
1 Like

Hey @msaglietto, great catch! :+1:

I’ve updated the starter code for both the Kafka and DNS server challenges, and confirmed that other challenges aren’t affected.

Thanks for spotting this!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.