The tests sometimes attempt to connect before the code is ready
Here are my logs:
[tester::#ZU2] Running tests for Stage #ZU2 (Handle concurrent clients)
[tester::#ZU2] $ ./your_program.sh
[your_program] Waiting for connection
[your_program] Connected to 0
[tester::#ZU2] [client-1] $ redis-cli PING
when “Waiting for connection” appears before [client-1] logs the test passes. However, sometimes this happens
[tester::#WY1] Running tests for Stage #WY1 (Respond to multiple PINGs)
[tester::#WY1] $ ./your_program.sh
[tester::#WY1] [client-1] $ redis-cli PING
[your_program] Waiting for connection
[tester::#WY1] Received: "" (no content received)
[tester::#WY1] ^ error
[tester::#WY1] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[tester::#WY1] Test failed
This is random and sometimes it gets passed this to the first test, but then that fails.
And here’s a snippet of my code: (formatter doesn’t have a zig option)
Runs perfectly locally for me. Can have multiple terminals open connected with redis-cli and do things like echo -e “PING\nPING” | redis-cli and see the correct number of PONGS
Yes, the tester terminates your server at the end of each stage.
One thing to watch out for: if sockets aren’t closed cleanly, the OS may take a short while to release the port (e.g. due to TIME_WAIT). This can cause issues when the next stage starts and your server tries to bind to the same port immediately.
I have attempted cleanup but it still isn’t working. You can see in this screenshot and in the one before that you posted, that the test is calling the [client-1] redis-cli .. before my code even starts.
I have updated my code with proper shutdown that I can see happening locally. There are still sockets with TIME-WAIT though so I don’t know what to do. The tests all passed once locally but when I submitted it didn’t pass
For context, our tester has been validated against the official Redis implementation (namely, the real Redis passes these tests), so we’re confident that ordering isn’t the root cause here.
Can I confirm how the sockets are supposed to be closed correctly?
If I get a read_len of zero that means that the client has closed the connection. I then call shutdown on the socket and close the fd. I can see the logs showing that this happens every time you call redis-cli PING but there is always a TIME-WAIT for each connection made when I exit the server.
Is this not how you’re supposed to cleanup a socket?
I can only view the first two solutions. They just seem to close the connection when they’re done. I might just have to drop libxev and do it another way