# Http-Server in C, Stage #EJ5, failed to read response (no content received)

**URL:** <https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122>\
**Category:** Bug Reports\
**Tags:** challenge:http-server\
**Created:** [January 11, 2025, 4:30pm UTC](https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122 "2025-01-11T16:30:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarjen](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/amarjen/32/3916_2.png) [@amarjen](https://forum.codecrafters.io/u/amarjen)\
**Post date:** [January 11, 2025, 4:30pm UTC](https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122/1 "2025-01-11T16:30:51Z")

</div>

I’m stuck on Stage #EJ5 (Concurrent connections)

For implemeting concurrency I use pthreads.h , but in doing so tests wont pass. I set up a macro CONCURRENT in order to be able to test against previous stages. When CONCURRENT == 0 , all tests go ok but this last one. For using threads I toggle it to 1, first tests fail. However in my machine works flawlessly without errors both ways, so not sure how to debug it.

Here are my logs:

```auto
[tester::#EJ5] Running tests for Stage #EJ5 (Concurrent connections)
[tester::#EJ5] Running program
[tester::#EJ5] $ ./your_program.sh
[tester::#EJ5] Creating 2 parallel connections
[tester::#EJ5] Creating connection 1
[your_program] Listening to port 4221...
[tester::#EJ5] Creating connection 2
[your_program] handling client...
[your_program] thread id: -1832678624
[tester::#EJ5] Sending first set of requests
[tester::#EJ5] client-2: $ curl -v http://localhost:4221/
[tester::#EJ5] client-2: > GET / HTTP/1.1
[tester::#EJ5] client-2: > Host: localhost:4221
[tester::#EJ5] client-2: >
[tester::#EJ5] client-2: Sent bytes: "GET / HTTP/1.1\r\nHost: localhost:4221\r\n\r\n"
[your_program] thread id: -1832821984
[your_program] handling client...
[tester::#EJ5] Failed to read response:
[tester::#EJ5] Received: "" (no content received)
[tester::#EJ5] ^ error
[tester::#EJ5] Error: Expected: HTTP-version, Received: ""
[tester::#EJ5] Test failed
[tester::#EJ5] Terminating program
[tester::#EJ5] Program terminated successfully

```

And here’s a snippet of my code, part of main inside the while loop and the handle\_client function:

```c
#if CONCURRENT == 1
        pthread_t thread_id;
        int s = pthread_create(&thread_id, NULL, handle_client, client_sock_ptr);
        if (s != 0) {
          printf("error of pthread_create id: %d\n", s);
        }
        pthread_detach(thread_id);
        printf("thread id: %d\n", thread_id);
#else
        printf("not threading...\n");
        handle_client(client_sock_ptr);
#endif

void *handle_client(void *client_socket)
{
    printf("handling client...\n");
    int sock = *(int *)client_socket;
    free(client_socket);

    char buffer[BUFFER_SIZE] = {0};
    int bytes_read = read(sock, buffer, BUFFER_SIZE - 1);

    HttpRequest req = {0};
    parse_http_request(buffer, &req);

    char response[4096] = {0};
    // CODECRAFTERS TEST DON'T GET TO THE NEXT LINE?
    handle_request(&req, response);

    if (DEBUG == 1) {
        printf("\nbytes read: %d\n", bytes_read);
        print_http_request(&req);
        printf("\nresponse:\n<<<<<<<\n%s\n>>>>>>>\n", response);
    }

    send(sock, response, strlen(response), 0);
    close(sock);

    return NULL;
}

```

---

<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:** [January 11, 2025, 11:02pm UTC](https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122/2 "2025-01-11T23:02:56Z")

</div>

I’ll take a look and get back to you by Monday.

---

<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:** [January 13, 2025, 11:06am UTC](https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122/4 "2025-01-13T11:06:54Z")

</div>

Hi @amarjen, the code can pass most stages if these lines are commented out:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/2/2de402c51fe56f3f28a7066c58fb586a1dacc044.png)

I’m not entirely sure why `httpHeaders` causes your code to hang. I’ll check with the team and get back to you with more details.

---

<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:** [January 22, 2025, 2:41pm UTC](https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122/5 "2025-01-22T14:41:56Z")

</div>

Will keep this thread open until we upgrade the C build pack.

---

<div class="post-metadata">

**Author:** ![olawaleibrahim](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/olawaleibrahim/32/4673_2.png) [@olawaleibrahim](https://forum.codecrafters.io/u/olawaleibrahim)\
**Post date:** [February 1, 2025, 4:43pm UTC](https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122/6 "2025-02-01T16:43:41Z")

</div>

any updates or upgrades? having this issue as well

---

<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:** [February 20, 2025, 3:59pm UTC](https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122/7 "2025-02-20T15:59:32Z")

</div>

Hey @amarjen, we’ve transitioned from **Alpine-based** buildpacks to **Debian-based** ones for the HTTP Server challenge in C.

I’ve also manually upgraded your repo. After pulling or cloning it again, you should have the latest setup. Let me know if you still run into any issues!

---

<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:** [February 20, 2025, 4:01pm UTC](https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122/8 "2025-02-20T16:01:22Z")

</div>

Hey @olawaleibrahim, the issue is specifically related to the **C buildpack**. Could you confirm if you’re also using C?

Also, feel free to [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link. It’ll be much easier to debug if I can run it directly!

---

<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:** [March 10, 2025, 9:52am UTC](https://forum.codecrafters.io/t/http-server-in-c-stage-ej5-failed-to-read-response-no-content-received/4122/10 "2025-03-10T09:52:09Z")

</div>

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