Skip to content

Commit 63eb094

Browse files
committed
Fix Linux CI segfault by using synchronous httplib task queue.
OpenSSL-enabled httplib runs request handlers in a thread pool by default, which can crash with statically linked OpenSSL on Linux amd64. Handle requests on the server thread instead.
1 parent a08a1fa commit 63eb094

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/httpserver_extension.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ namespace duckdb
2626

2727
using namespace duckdb_yyjson; // NOLINT(*-build-using-namespace)
2828

29+
// httplib defaults to a thread pool when OpenSSL is enabled. With statically
30+
// linked OpenSSL on Linux this can segfault in worker threads, so handle
31+
// requests synchronously on the server thread instead.
32+
class SynchronousTaskQueue : public duckdb_httplib_openssl::TaskQueue
33+
{
34+
public:
35+
bool enqueue(std::function<void()> fn) override
36+
{
37+
fn();
38+
return true;
39+
}
40+
41+
void shutdown() override
42+
{
43+
}
44+
};
45+
2946
struct HttpServerState
3047
{
3148
std::unique_ptr<duckdb_httplib_openssl::Server> server;
@@ -384,6 +401,12 @@ namespace duckdb
384401
std::string error_message = "DB::Exception: " + std::string(ex.what());
385402
res.set_content(error_message, "text/plain");
386403
}
404+
catch (const std::exception &ex)
405+
{
406+
res.status = 500;
407+
std::string error_message = "DB::Exception: " + std::string(ex.what());
408+
res.set_content(error_message, "text/plain");
409+
}
387410
}
388411

389412
void HttpServerStart(shared_ptr<DatabaseInstance> db, string_t host, int32_t port, string_t auth = string_t())
@@ -395,6 +418,7 @@ namespace duckdb
395418

396419
global_state.db_instance = db;
397420
global_state.server = make_uniq<duckdb_httplib_openssl::Server>();
421+
global_state.server->new_task_queue = []() { return new SynchronousTaskQueue(); };
398422
global_state.is_running = true;
399423
global_state.auth_token = auth.GetString();
400424

0 commit comments

Comments
 (0)