Stuck on Concurrent connections #EJ5: Waiting for response even after getting all responses with connection close header

Client continues to wait for response despite all responses including ‘Connection: close’ header.
I made the request using

(sleep 3 && printf "GET / HTTP/1.1\r\n\r\n") | nc localhost 4221 & (sleep 3 && printf "GET / HTTP/1.1\r\n\r\n") | nc localhost 4221 & (sleep 3 && printf "GET / HTTP/1.1\r\n\r\n") | nc localhost 4221 &

Check out this video — I hit Ctrl+C to close the connection.

Hey @homocodian, the issue seems to stem from this line:

I added this log:

std::cout << "⛳ Number of hardware threads: " << std::thread::hardware_concurrency() << std::endl;

Our test runner only has two CPU cores:

You might want to increase the thread pool size so it can handle multiple connections concurrently.

Thanks for you time but it didn’t work.

  • curl -v http://localhost:4221 → works and exits cleanly :white_check_mark:
  • nc localhost 4221 → hangs :cross_mark: even though the response includes Content-Length: 0 and Connection: close

@homocodian Could you confirm what error messages you are seeing for Concurrent connections #ej5 after adjusting to ThreadPool threadPool(5);?

Also, could you try adding the -q 1 flag to your nc command and let me know if that changes anything?

(sleep 3 && printf "GET / HTTP/1.1\r\n\r\n") | nc -q 1 localhost 4221 &

Additionally, would you mind confirming where in your code you are closing the client connection?

I have doubled the size of thread pool.

(sleep 3 && printf "GET / HTTP/1.1\r\n\r\n") | nc -q 1 localhost 4221 &

still same thing.

in client’s destructor

@homocodian Does your server print Client closed?

If so, your server is probably working correctly, and it’s just that your local nc is hanging.

Could you confirm if your code is able to pass our tests now with a larger thread pool?

Yes, the tests passed successfully, although I only just ran them now

1 Like

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