Fix race condition in HTTP server