Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Concurrent Connections

Up until now, we’ve only sent one request at a time. But a real HTTP server must handle multiple clients simultaneously!

Imagine a slow client connects to your server and starts sending a request, but pauses halfway through. If your server processes connections synchronously (blocking on one client until they finish before accepting the next), that one slow client just froze your entire server!

To handle real-world traffic, your server must be able to juggle multiple connections at once.

Your Task

Ensure your server can handle concurrent connections. You can achieve this using multi-threading (e.g., spawning a new thread per accepted socket connection) or asynchronous I/O (e.g., using epoll/kqueue or an async runtime like Tokio or Node.js).

How we test this: The tester will open two connections at the exact same time. It will send a slow, incomplete request on Connection 1. While Connection 1 is sitting idle waiting for more data, the tester will send a complete, fast request on Connection 2.

Your server must respond to Connection 2 immediately, without waiting for Connection 1 to finish!


Important

Run the below docker command to test your solution.

docker run \
  --rm \
  --add-host host.docker.internal:host-gateway \
  codeberg.org/level0/buildit/http-server:latest \
  --addr host.docker.internal:8080 \
  --until concurrent_connections