# NH4 - First request test passes but subsequent request test fails

**URL:** <https://forum.codecrafters.io/t/nh4-first-request-test-passes-but-subsequent-request-test-fails/9729>\
**Category:** Challenges\
**Tags:** challenge:kafka\
**Created:** [April 30, 2025, 8:15pm UTC](https://forum.codecrafters.io/t/nh4-first-request-test-passes-but-subsequent-request-test-fails/9729 "2025-04-30T20:15:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mzaman07](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mzaman07/32/9259_2.png) [@mzaman07](https://forum.codecrafters.io/u/mzaman07)\
**Post date:** [April 30, 2025, 8:15pm UTC](https://forum.codecrafters.io/t/nh4-first-request-test-passes-but-subsequent-request-test-fails/9729/1 "2025-04-30T20:15:05Z")

</div>

Hi I’m stuck on Serial requests #NH4. When I run my code against the tests I can see the first request having the response. Subsequent requests report the following and I’m not sure if the responses from my end are being received for tests. Here is what the tester tells me.

```auto
[tester::#NH4] Running tests for Stage #NH4 (Concurrent Clients - Serial requests)
[tester::#NH4] $ ./your_program.sh /tmp/server.properties
[tester::#NH4] Connecting to broker at: localhost:9092
[your_program] Logs from your program will appear here!
[your_program] test before read
[tester::#NH4] Connection to broker at localhost:9092 successful
[tester::#NH4] Sending request 1 of 3: "ApiVersions" (version: 4) request (Correlation id: 2012015867)
[tester::#NH4] Hexdump of sent "ApiVersions" request: 
[tester::#NH4] Idx | Hex | ASCII
[tester::#NH4] -----+-------------------------------------------------+-----------------
[tester::#NH4] 0000 | 00 00 00 23 00 12 00 04 77 ec ec fb 00 09 6b 61 | ...#....w.....ka
[tester::#NH4] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli..kafka-c
[tester::#NH4] 0020 | 6c 69 04 30 2e 31 00 | li.0.1.
[tester::#NH4] 
[your_program] test number of bytes 39
[tester::#NH4] Hexdump of received "ApiVersions" response: 
[tester::#NH4] Idx | Hex | ASCII
[tester::#NH4] -----+-------------------------------------------------+-----------------
[tester::#NH4] 0000 | 00 00 00 13 77 ec ec fb 00 00 02 00 12 00 00 00 | ....w...........
[tester::#NH4] 0010 | 04 00 00 00 00 00 00 | .......
[tester::#NH4] 
[tester::#NH4] [Decoder] - .ResponseHeader
[tester::#NH4] [Decoder] - .correlation_id (2012015867)
[tester::#NH4] [Decoder] - .ResponseBody
[tester::#NH4] [Decoder] - .error_code (0)
[tester::#NH4] [Decoder] - .num_api_keys (1)
[tester::#NH4] [Decoder] - .ApiKeys[0]
[tester::#NH4] [Decoder] - .api_key (18)
[tester::#NH4] [Decoder] - .min_version (0)
[tester::#NH4] [Decoder] - .max_version (4)
[tester::#NH4] [Decoder] - .TAG_BUFFER
[tester::#NH4] [Decoder] - .throttle_time_ms (0)
[tester::#NH4] [Decoder] - .TAG_BUFFER
[tester::#NH4] ✓ Correlation ID: 2012015867
[tester::#NH4] ✓ Error code: 0 (NO_ERROR)
[tester::#NH4] ✓ API keys array is non-empty
[tester::#NH4] ✓ API version 4 is supported for API_VERSIONS
[tester::#NH4] ✓ Test 1 of 3: Passed
[tester::#NH4] Sending request 2 of 3: "ApiVersions" (version: 4) request (Correlation id: 1521498597)
[your_program] test writeout bytes 25
[your_program] 00000000 00 00 00 13 77 ec ec fb 00 00 02 00 12 00 00 00 |....w...........|
[tester::#NH4] Hexdump of sent "ApiVersions" request: 
[tester::#NH4] Idx | Hex | ASCII
[tester::#NH4] -----+-------------------------------------------------+-----------------
[tester::#NH4] 0000 | 00 00 00 23 00 12 00 04 5a b0 39 e5 00 09 6b 61 | ...#....Z.9...ka
[tester::#NH4] 0010 | 66 6b 61 2d 63 6c 69 00 0a 6b 61 66 6b 61 2d 63 | fka-cli..kafka-c
[tester::#NH4] 0020 | 6c 69 04 30 2e 31 00 | li.0.1.
[tester::#NH4] 
[tester::#NH4] Hexdump of received "ApiVersions" response: 
[tester::#NH4] Idx | Hex | ASCII
[tester::#NH4] -----+-------------------------------------------------+-----------------
[tester::#NH4] 0000 | 00 00 00 00 | ....
[tester::#NH4] 
[your_program] 00000010 04 00 00 00 00 00 00 00 00 |.........|
[tester::#NH4] [Decoder] - .ResponseHeader
[tester::#NH4] Received:
[tester::#NH4] Hex (bytes 0--1) | ASCII
[tester::#NH4] ------------------------------------------------+------------------
[tester::#NH4] | 
[tester::#NH4] ^ ^
[tester::#NH4] Error: Expected int32 length to be 4 bytes, got 0 bytes
[tester::#NH4] Context:
[tester::#NH4] - ApiVersions v3
[tester::#NH4] - Response Header
[tester::#NH4] - correlation_id
[tester::#NH4] - INT32
[tester::#NH4] 
[tester::#NH4] Test failed
[tester::#NH4] Terminating program
[tester::#NH4] Program terminated successfully

```

I have looked at the test code [here](https://github.com/codecrafters-io/kafka-tester/blob/e669dd0f49b10a2ec3d5e2e8ae1daa05a0f5535b/internal/stagec1.go#L15) and its not clear what the problem is from my end because the first test is passing. Thank you for your guidance.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 30, 2025, 8:24pm UTC](https://forum.codecrafters.io/t/nh4-first-request-test-passes-but-subsequent-request-test-fails/9729/3 "2025-04-30T20:24:23Z")

</div>

Hey @mzaman07, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![mzaman07](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mzaman07/32/9259_2.png) [@mzaman07](https://forum.codecrafters.io/u/mzaman07)\
**Post date:** [May 1, 2025, 6:20pm UTC](https://forum.codecrafters.io/t/nh4-first-request-test-passes-but-subsequent-request-test-fails/9729/4 "2025-05-01T18:20:10Z")

</div>

Here is the [github repo](https://github.com/mzaman07/codecrafters-kafka-go)

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [May 2, 2025, 10:38am UTC](https://forum.codecrafters.io/t/nh4-first-request-test-passes-but-subsequent-request-test-fails/9729/6 "2025-05-02T10:38:56Z")

</div>

@mzaman07 The task for this stage is to handle multiple requests over the same connection. It looks like that part isn’t implemented yet.

Hint: you may need a loop inside your `handleConn` function.

---

<div class="post-metadata">

**Author:** ![mzaman07](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mzaman07/32/9259_2.png) [@mzaman07](https://forum.codecrafters.io/u/mzaman07)\
**Post date:** [May 2, 2025, 6:36pm UTC](https://forum.codecrafters.io/t/nh4-first-request-test-passes-but-subsequent-request-test-fails/9729/8 "2025-05-02T18:36:55Z")

</div>

Oh I see I was under the impression that the subsequent requests were using the same tcp connection and would just wait for the subsequent request would come in. This is what created the confusion. I’ll try it out thanks.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [May 11, 2025, 9:53pm UTC](https://forum.codecrafters.io/t/nh4-first-request-test-passes-but-subsequent-request-test-fails/9729/9 "2025-05-11T21:53:24Z")

</div>

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