[C#] Stuck at stage #WA6 - Parse CorrelationId

Hi,

When I run the command locally (echo -n “00000023001200046f7fc66100096b61666b612d636c69000a6b61666b612d636c6904302e3100” | xxd -r -p | netcat localhost 9092 | hexdump -C)

The server response is :
00000000 00 00 00 04 6f 7f c6 61 |…o…a|
00000008

However, the testrunner give me this error :eyes::
[tester::#WA6] Sending “ApiVersions” (version: 4) request (Correlation id: 292377159)
[tester::#WA6] Hexdump of sent “ApiVersions” request:
[tester::#WA6] Idx | Hex | ASCII
[tester::#WA6] -----±------------------------------------------------±----------------
[tester::#WA6] 0000 | 00 00 00 23 00 12 00 04 11 6d 52 47 00 09 6b 61 | …#…mRG…ka
[tester::#WA6] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli…kafka-c
[tester::#WA6] 0020 | 6c 69 04 30 2e 31 00 | li.0.1.
[tester::#WA6]
[tester::#WA6] Hexdump of received “ApiVersions” response:
[tester::#WA6] Idx | Hex | ASCII
[tester::#WA6] -----±------------------------------------------------±----------------
[tester::#WA6] |
[tester::#WA6]
[tester::#WA6] [Decoder] - .Response
[tester::#WA6] [Decoder] Received:
[tester::#WA6] [Decoder] Hex (bytes 0–1) | ASCII
[tester::#WA6] [Decoder] ------------------------------------------------±-----------------
[tester::#WA6] [Decoder] |
[tester::#WA6] [Decoder] ^ ^
[tester::#WA6] [Decoder] Error: Expected int32 length to be 4 bytes, got 0 bytes
[tester::#WA6] [Decoder] Context:
[tester::#WA6] [Decoder] - response
[tester::#WA6] [Decoder] - message length
[tester::#WA6] [Decoder] - INT32
[tester::#WA6] [Decoder]
[tester::#WA6] [Decoder] Test failed

I don’t understand why, because locally it seems fine, but testrunner says error :frowning:

To see the code, please head to my Github

Since the response has no bytes, you’re probably exiting early for some reason. I’m suspicious of the line: while (networkStream.DataAvailable).
Documentation for DataAvailable (emphasis mine):

Gets a value that indicates whether data is available on the NetworkStream to be immediately read.

I’d suspect that there’s a race condition, if that line is hit after the connection is established but before getting the first byte of the request. In which case running it locally may just be fast enough to not hit that scenario, while the tester runs it in a way with a bit more delay that does hit that scenario.

I’d suggest just having a while (true) and rely on an exception being thrown on a read request to tell when the client is disconnected, and see if that works.

1 Like

Thank you for your reply, I have tried it with the while true, but it give me the same problem :frowning:

Hey @NancyTang50, I tried running your code against the previous stages, but it’s actually no longer passing the previous stage #NV3 (Send Correlation ID).

Suggestions:

  1. Use our CLI to test against previous stages by running:
codecrafters test --previous
  1. Focus on fixing the early stages first, as later stages depend on them.

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

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