Go kafaka challange

I was stuck on Stage #NV3.

I manage to pass the tests by closing the conn with conn.Close()

Here is my code snippet:

conn, err := l.Accept()
	if err != nil {
		fmt.Println("Error accepting connection: ", err.Error())
		os.Exit(1)
	}
	defer conn.Close()

	res := Res{
		message_size: 0,
		header: Header{
			correlation_id: 7,
		},
	}

	var buf bytes.Buffer
	binary.Write(&buf, binary.BigEndian, res.message_size)
	binary.Write(&buf, binary.BigEndian, res.header.correlation_id)

	conn.Write(buf.Bytes())

Before i passed the test here is the log for the failing test

remote: [tester::#NV3] [Encoder]     - APIVersion (4)
remote: [tester::#NV3] [Encoder]     - CorrelationID (7)
remote: [tester::#NV3] [Encoder]     - ClientID (kafka-tester)
remote: [tester::#NV3] [Encoder]   - Body
remote: [tester::#NV3] [Encoder]     - ClientSoftwareName (kafka-cli)
remote: [tester::#NV3] [Encoder]     - ClientSoftwareVersion (0.1)
remote: [tester::#NV3] [client] Sending "ApiVersions" request
remote: [tester::#NV3] [client] Hexdump of sent "ApiVersions" request:
remote: [tester::#NV3] [client] Idx  | Hex                                             | ASCII
remote: [tester::#NV3] [client] -----+-------------------------------------------------+-----------------
remote: [tester::#NV3] [client] 0000 | 00 00 00 26 00 12 00 04 00 00 00 07 00 0c 6b 61 | ...&..........ka
remote: [tester::#NV3] [client] 0010 | 66 6b 61 2d 74 65 73 74 65 72 00 0a 6b 61 66 6b | fka-tester..kafk
remote: [tester::#NV3] [client] 0020 | 61 2d 63 6c 69 04 30 2e 31 00                   | a-cli.0.1.
remote: [tester::#NV3] [client]
remote: [tester::#NV3] error reading from connection: read tcp 127.0.0.1:33252->127.0.0.1:9092: read: connection reset by peer
remote: [tester::#NV3] Test failed
remote: [tester::#NV3] Terminating program
remote: [tester::#NV3] Program terminated successfully                               
                                              

I dont understand why adding the line defer conn.Close() solved my issue, i add the line suspecting my the tcp is stil wating for write if i dont close the connection and timing out waiting but i dont think i fully understand why it worked. so any explanation would be appreciated :blush: !!!

Hey @bm-197, this is actually a bug on our end. We’re currently working on a fix in this PR.

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