Skip to content

Commit b3d49ff

Browse files
rustyconoverclaude
andcommitted
fix: return from httpserve_start only once the server accepts connections
httpserve_start returned as soon as the listener thread was spawned. With the httplib bundled in DuckDB 1.5, a stop() that arrives before the accept loop starts is ignored, so an httpserve_stop() right after httpserve_start could wait forever on a listener that never ends (2 of 30 runs of SELECT httpserve_start(...), httpserve_stop() hung on v1.5). httpserve_start now waits until the server is ready, and reports a listen that fails after binding as an error. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent f4939d7 commit b3d49ff

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎src/httpserver_extension.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,21 @@ namespace duckdb
616616
if (!global_state.server->listen_after_bind()) {
617617
global_state.is_running = false;
618618
} });
619+
620+
// Return only once the accept loop is running. Some httplib versions ignore a stop() that arrives
621+
// before then, which would leave httpserve_stop() waiting forever on a listener that never ends.
622+
// This also reports a listen that fails after binding.
623+
global_state.server->wait_until_ready();
624+
if (!global_state.server->is_running())
625+
{
626+
global_state.server_thread->join();
627+
global_state.server_thread.reset();
628+
global_state.server.reset();
629+
global_state.db_instance = nullptr;
630+
global_state.allocator.reset();
631+
global_state.is_running = false;
632+
throw IOException("Failed to start HTTP server on " + host_str + ":" + std::to_string(port));
633+
}
619634
}
620635
return port;
621636
}

0 commit comments

Comments
 (0)