Fix race condition in ServeHTTP