Skip to content
Merged

fix #23

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 .gitea/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ jobs:
shell: bash
run: |
set -o pipefail
bazel test //framework/... --test_output=errors --test_verbose_timeout_warnings 2>&1 | tee ci-test.log
bazel test -c opt --strip=always //framework/... --test_output=errors --test_verbose_timeout_warnings 2>&1 | tee ci-test.log
- name: HTTP concurrency benchmark smoke test
id: concurrency_benchmark
shell: bash
run: |
set -o pipefail
bazel run //framework/tests:concurrency_benchmark -- \
bazel run -c opt --strip=always //framework/tests:concurrency_benchmark -- \
--server-threads 2 --concurrency 8 --requests 80 --warmup 8 \
2>&1 | tee ci-concurrency-benchmark.log
- name: Publish test and benchmark summary
Expand Down Expand Up @@ -138,5 +138,5 @@ jobs:
run: |
cp .bazelrc ./example
cd example
bazel build app
bazel build -c opt --strip=always app
cd ..
6 changes: 3 additions & 3 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ jobs:
shell: bash
run: |
set -o pipefail
bazel test //framework/... --test_output=errors --test_verbose_timeout_warnings --verbose_failures 2>&1 | tee ci-test.log
bazel test -c opt --strip=always //framework/... --test_output=errors --test_verbose_timeout_warnings --verbose_failures 2>&1 | tee ci-test.log
- name: HTTP concurrency benchmark smoke test
id: concurrency_benchmark
shell: bash
run: |
set -o pipefail
bazel run //framework/tests:concurrency_benchmark -- \
bazel run -c opt --strip=always //framework/tests:concurrency_benchmark -- \
--server-threads 2 --concurrency 8 --requests 80 --warmup 8 \
2>&1 | tee ci-concurrency-benchmark.log
- name: Upload failed test logs
Expand Down Expand Up @@ -161,7 +161,7 @@ jobs:
set -o pipefail
cp .bazelrc ./example
cd example
bazel build app 2>&1 | tee ../ci-build.log
bazel build -c opt --strip=always app 2>&1 | tee ../ci-build.log
- name: Upload failed example build logs
if: failure()
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "khttpd",
version = "0.5.2",
version = "0.5.3",
)

bazel_dep(name = "platforms", version = "1.1.0")
Expand Down
6 changes: 6 additions & 0 deletions framework/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ void Server::run() {

IoContextPool::instance().get_io_context().run();

// stop() only signals the pool so it can be called from an Asio worker
// without joining itself. The run() caller is the owner of the Server
// lifetime, so wait for every worker before returning and allowing Server's
// handlers, routers, and acceptor to be destroyed.
IoContextPool::instance().shutdown();

spdlog::info("Server workers stopped.");
}

Expand Down
5 changes: 5 additions & 0 deletions framework/tests/server_stability_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>

#include "framework/context/http_context.hpp"
#include "framework/io_context_pool.hpp"
#include "framework/server.hpp"

namespace beast = boost::beast;
Expand Down Expand Up @@ -112,6 +113,10 @@ TEST(ServerStabilityTest, HandlesManyConcurrentRequests) {
server_thread.join();
}

// Server::run() must not return while the process-wide pool still has
// workers executing handlers that reference the server and its routers.
EXPECT_EQ(khttpd_fw::IoContextPool::instance().get_thread_count(), 0U);

constexpr int total_requests = kThreadCount * kRequestsPerThread;
EXPECT_EQ(successes.load(), total_requests);
EXPECT_EQ(handled.load(), total_requests);
Expand Down
Loading