Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ concurrency:
jobs:
duckdb-stable-build:
name: Build extension binaries
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.5.4
with:
duckdb_version: main
ci_tools_version: main
duckdb_version: v1.5.4
ci_tools_version: v1.5.4
extension_name: httpserver
2 changes: 1 addition & 1 deletion duckdb
Submodule duckdb updated 4875 files
29 changes: 27 additions & 2 deletions src/httpserver_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ namespace duckdb

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

// httplib defaults to a thread pool when OpenSSL is enabled. With statically
// linked OpenSSL on Linux this can segfault in worker threads, so handle
// requests synchronously on the server thread instead.
class SynchronousTaskQueue : public duckdb_httplib_openssl::TaskQueue
{
public:
bool enqueue(std::function<void()> fn) override
{
fn();
return true;
}

void shutdown() override
{
}
};

struct HttpServerState
{
std::unique_ptr<duckdb_httplib_openssl::Server> server;
Expand Down Expand Up @@ -384,6 +401,12 @@ namespace duckdb
std::string error_message = "DB::Exception: " + std::string(ex.what());
res.set_content(error_message, "text/plain");
}
catch (const std::exception &ex)
{
res.status = 500;
std::string error_message = "DB::Exception: " + std::string(ex.what());
res.set_content(error_message, "text/plain");
}
}

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

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

Expand Down Expand Up @@ -580,9 +604,10 @@ namespace duckdb

static void LoadInternal(ExtensionLoader &loader)
{
auto db = loader.GetDatabaseInstance().shared_from_this();
auto httpserve_start = ScalarFunction(
"httpserve_start", {LogicalType::VARCHAR, LogicalType::INTEGER, LogicalType::VARCHAR}, LogicalType::VARCHAR,
[&](DataChunk &args, ExpressionState &state, Vector &result)
[db](DataChunk &args, ExpressionState &state, Vector &result)
{
auto &host_vector = args.data[0];
auto &port_vector = args.data[1];
Expand All @@ -592,7 +617,7 @@ namespace duckdb
{
auto port = ((int32_t *)port_vector.GetData())[0];
auto auth = ((string_t *)auth_vector.GetData())[0];
HttpServerStart(loader.GetDatabaseInstance().shared_from_this(), host, port, auth);
HttpServerStart(db, host, port, auth);
return StringVector::AddString(result, "HTTP server started on " + host.GetString() + ":" +
std::to_string(port)); });
});
Expand Down
Loading