Problem reading from client_fd on Parse Correlation ID #WA6

I keep getting

[tester::#NV3] error reading from connection: read tcp 127.0.0.1:37916->127.0.0.1:9092: read: connection reset by peer
[tester::#NV3] Test failed

as soon as I do any read of any size from client_fd

if I comment out all reads then #NV3 passes with hardcoded 7 for correlation_id, but there is no way to echo correlation_id from client request so it fails #WA6.

I also tried draining all request, before writing and after writing but it does not change anything.
On logs I can see that I’m receiving expected data from request.

Another thing I tried was writing before doing any read and also get same message.

Thanks the post! I’ll take a look shortly.

1 Like

I’m solving the challenge with cpp

this is a more complete version of logs

[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
[your_program] Logs from your program will appear here!
[your_program] Waiting for a client to connect...
[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] 
[your_program] Client connected
[your_program] req_message_size: 0 0 0 23 
[tester::#NV3] error reading from connection: read tcp 127.0.0.1:50242->127.0.0.1:9092: read: connection reset by peer
[tester::#NV3] Test failed
[tester::#NV3] Terminating program
[your_program] 35
[your_program] req_api_key: 0 12 
[your_program] req_api_version: 0 4 
[your_program] req_correlation_id: 0 0 0 7 
[your_program] res_message_size: 0 0 0 0 
[your_program] res_correlation_id: 0 0 0 7 
[tester::#NV3] Program terminated successfully

Hi @RedJocker, you can create a buffer large enough to hold the entire request, read into it, and then read from the buffer as needed:

This approach will ensure there are no errors.

1 Like

Thanks andy1li that did help.

I’m still doing several small reads, but what I found out was that I was not draining enough data from request which was causing issues.

Before I was calculating draining size with

size_t to_drain = req_message_size - 4 - 2 - 2 - 4;

discounting the size of the parts that were already read.
Now I tried

size_t to_drain = req_message_size - 2 - 2 - 4;

and it worked.

I’m still trying to figure out why, but maybe the message_size itself is not considered part of the message? I don’t know, but It is working now.
But I would not figure this out without trying your code first.

1 Like

Yep, message_size denotes the number of bytes remaining to be read.

You might find BinspecVisualizer helpful when trying to understand Kafka requests and responses.

1 Like

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