Skip to content

Commit abbb2de

Browse files
committed
Merge branch 'master' into v13 branch
2 parents a48c3e2 + 773faaa commit abbb2de

18 files changed

Lines changed: 280 additions & 159 deletions

.github/workflows/build_and_test.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ jobs:
3131
- { os: windows-latest, compiler: msvc, cxx_stdlib: msvc }
3232

3333
steps:
34+
3435
- name: Output Infos
3536
run: |
3637
echo $GIT_REF
3738
echo $GIT_EVENT_REF
3839
echo $GIT_EVENT_TYPE
3940
40-
- uses: actions/checkout@v5
41+
- uses: actions/checkout@v6
42+
4143
- name: Prepare dependencies
4244
run: |
4345
if [ "$RUNNER_OS" == "Linux" ]; then
@@ -135,8 +137,8 @@ jobs:
135137
shell: bash
136138

137139
- name: Save report
138-
uses: actions/upload-artifact@v4
139-
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc' && matrix.cxx_stdlib == 'libstdc++' && matrix.asio_type == 'boost' && !startsWith(github.ref, 'refs/heads/v')
140+
uses: actions/upload-artifact@v6
141+
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc' && matrix.cxx_stdlib == 'libstdc++' && matrix.asio_type == 'boost' && !startsWith(github.ref, 'refs/tags/v')
140142
with:
141143
name: coveralls.json
142144
path: coveralls.json
@@ -157,8 +159,8 @@ jobs:
157159
shell: bash
158160

159161
- name: Upload Linux packages
160-
uses: actions/upload-artifact@v4
161-
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc' && matrix.cxx_stdlib == 'libstdc++' && matrix.asio_type == 'boost' && startsWith(github.ref, 'refs/heads/v')
162+
- uses: actions/upload-artifact@v6
163+
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc' && matrix.cxx_stdlib == 'libstdc++' && matrix.asio_type == 'boost' && startsWith(github.ref, 'refs/tags/v')
162164
with:
163165
name: packages
164166
overwrite: true

.github/workflows/build_bazel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
# ubuntu-18.04 & mac-os do not work due to compile error on asio
2727
# windows-2019 not included to spare free minutes
2828
steps:
29-
- uses: actions/checkout@v5
29+
- uses: actions/checkout@v6
3030
- name: Prepare dependencies
3131
run: |
3232
if [ "$RUNNER_OS" == "Linux" ]; then

.github/workflows/cifuzz.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
fuzz-seconds: 800
2626
output-sarif: true
2727
- name: Upload Crash
28-
uses: actions/upload-artifact@v4
28+
uses: actions/upload-artifact@v6
2929
if: failure() && steps.build.outcome == 'success'
3030
with:
3131
name: artifacts

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
5959
steps:
6060
- name: Checkout repository
61-
uses: actions/checkout@v5
61+
uses: actions/checkout@v6
6262

6363
# Install dependencies
6464
- name: Prepare dependencies

.github/workflows/doxygen-gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout 🛎️
16-
uses: actions/checkout@v5
16+
uses: actions/checkout@v6
1717
- name: Prepare dependencies
1818
run: sudo apt-get update && sudo apt-get -yq install libasio-dev doxygen mkdocs graphviz zlib1g-dev gcc clang make cmake python3 python3-pip git openssl libssl-dev
1919
- name: prepate pip dependencies

.github/workflows/submit_coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
if: github.event.workflow_run.conclusion == 'success'
1717
steps:
1818
- name: Download artifact
19-
uses: dawidd6/action-download-artifact@v11
19+
uses: dawidd6/action-download-artifact@v14
2020
with:
2121
workflow: ${{ github.event.workflow_run.workflow_id }}
2222
workflow_conclusion: success

CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ project(Crow
1111

1212
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1313

14-
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake)
15-
1614
# Make sure Findasio.cmake module is found
1715
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
1816

@@ -59,12 +57,17 @@ option(CROW_RETURNS_OK_ON_HTTP_OPTIONS_REQUEST
5957

6058
option(CROW_ENABLE_SSL "Enable Crow's SSL feature for supporting https" OFF)
6159
option(CROW_ENABLE_COMPRESSION "Enable Crow's Compression feature for supporting compressed http content" OFF)
60+
option(CROW_ENABLE_TSAN "Enable ThreadSanitizer" OFF)
61+
62+
if(CROW_GENERATE_SBOM OR CROW_BUILD_TESTS)
63+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake)
64+
endif ()
6265

6366
if(CROW_GENERATE_SBOM)
6467
CPMAddPackage(
6568
NAME cmake-sbom
6669
GITHUB_REPOSITORY DEMCON/cmake-sbom
67-
GIT_TAG v1.3.0
70+
GIT_TAG v1.4.0
6871
DOWNLOAD_ONLY YES
6972
)
7073
list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/_deps/cmake-sbom-src/cmake")
@@ -80,6 +83,16 @@ if(CROW_GENERATE_SBOM)
8083
)
8184
endif()
8285

86+
if(CROW_ENABLE_TSAN)
87+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
88+
message(STATUS "ThreadSanitizer enabled")
89+
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer)
90+
add_link_options(-fsanitize=thread)
91+
else()
92+
message(WARNING "ThreadSanitizer is exclusive to Clang and cannot be used with any other compilers")
93+
endif()
94+
endif()
95+
8396
#####################################
8497
# Define Targets
8598
#####################################

include/crow/app.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ namespace crow
619619

620620
void close_websockets()
621621
{
622+
std::lock_guard<std::mutex> lock{websockets_mutex_};
622623
for (auto websocket : websockets_)
623624
{
624625
CROW_LOG_INFO << "Quitting Websocket: " << websocket;
@@ -629,11 +630,13 @@ namespace crow
629630

630631
void add_websocket(std::shared_ptr<websocket::connection> conn)
631632
{
633+
std::lock_guard<std::mutex> lock{websockets_mutex_};
632634
websockets_.push_back(conn);
633635
}
634636

635637
void remove_websocket(std::shared_ptr<websocket::connection> conn)
636638
{
639+
std::lock_guard<std::mutex> lock{websockets_mutex_};
637640
websockets_.erase(std::remove(websockets_.begin(), websockets_.end(), conn), websockets_.end());
638641
}
639642

@@ -846,6 +849,7 @@ namespace crow
846849
bool server_started_{false};
847850
std::condition_variable cv_started_;
848851
std::mutex start_mutex_;
852+
std::mutex websockets_mutex_; ///< \brief mutex to protect websockets_
849853
std::vector<std::shared_ptr<websocket::connection>> websockets_;
850854
};
851855

include/crow/common.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,19 +280,19 @@ namespace crow
280280
struct routing_handle_result
281281
{
282282
bool catch_all{false};
283-
uint16_t rule_index;
284-
std::vector<uint16_t> blueprint_indices;
283+
size_t rule_index;
284+
std::vector<size_t> blueprint_indices;
285285
routing_params r_params;
286286
HTTPMethod method;
287287

288288
routing_handle_result() {}
289289

290-
routing_handle_result(uint16_t rule_index_, std::vector<uint16_t> blueprint_indices_, routing_params r_params_):
290+
routing_handle_result(size_t rule_index_, std::vector<size_t> blueprint_indices_, routing_params r_params_):
291291
rule_index(rule_index_),
292292
blueprint_indices(blueprint_indices_),
293293
r_params(r_params_) {}
294294

295-
routing_handle_result(uint16_t rule_index_, std::vector<uint16_t> blueprint_indices_, routing_params r_params_, HTTPMethod method_):
295+
routing_handle_result(size_t rule_index_, std::vector<size_t> blueprint_indices_, routing_params r_params_, HTTPMethod method_):
296296
rule_index(rule_index_),
297297
blueprint_indices(blueprint_indices_),
298298
r_params(r_params_),

include/crow/http_connection.h

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,13 @@ namespace crow
128128
{
129129
continue_requested = true;
130130
buffers_.clear();
131-
static std::string expect_100_continue = "HTTP/1.1 100 Continue\r\n\r\n";
131+
static const std::string expect_100_continue = "HTTP/1.1 100 Continue\r\n\r\n";
132132
buffers_.emplace_back(expect_100_continue.data(), expect_100_continue.size());
133-
do_write_sync(buffers_);
133+
error_code ec = do_write_sync(buffers_);
134+
if (ec)
135+
{
136+
CROW_LOG_ERROR << ec << " buffer write error happened while handling sending continuation buffer header";
137+
}
134138
}
135139
}
136140

@@ -299,7 +303,12 @@ namespace crow
299303
while (is.gcount() > 0)
300304
{
301305
buffers[0] = asio::buffer(buf, is.gcount());
302-
do_write_sync(buffers);
306+
error_code ec = do_write_sync(buffers);
307+
if (ec) {
308+
CROW_LOG_ERROR << ec << " - buffer write error happened while sending content of file "
309+
<< res.file_info.path << ". Writing stopped premature.";
310+
break;
311+
}
303312
is.read(buf, sizeof(buf));
304313
}
305314
}
@@ -318,13 +327,16 @@ namespace crow
318327

319328
void do_write_general()
320329
{
330+
error_code ec;
321331
if (res.body.length() < res_stream_threshold_)
322332
{
323333
res_body_copy_.swap(res.body);
324334
buffers_.emplace_back(res_body_copy_.data(), res_body_copy_.size());
325335

326-
do_write_sync(buffers_);
327-
336+
ec = do_write_sync(buffers_);
337+
if (ec) {
338+
CROW_LOG_ERROR << ec << " - buffer write error happened while sending response. Writing stopped premature.";
339+
}
328340
if (need_to_start_read_after_complete_)
329341
{
330342
need_to_start_read_after_complete_ = false;
@@ -334,7 +346,10 @@ namespace crow
334346
}
335347
else
336348
{
337-
asio::write(adaptor_.socket(), buffers_); // Write the response start / headers
349+
asio::write(adaptor_.socket(), buffers_,ec); // Write the response start / headers
350+
if (ec) {
351+
CROW_LOG_ERROR << ec << "- buffer write error happened while sending response start / headers. Writing stopped premature.";
352+
}
338353
cancel_deadline_timer();
339354
if (res.body.length() > 0)
340355
{
@@ -345,7 +360,11 @@ namespace crow
345360
{
346361
size_t to_transfer = CROW_MIN(16384UL, length - transferred);
347362
buffers[0] = asio::const_buffer(data + transferred, to_transfer);
348-
do_write_sync(buffers);
363+
ec = do_write_sync(buffers);
364+
if (ec) {
365+
CROW_LOG_ERROR << ec << " - " << transferred << " - buffer write error happened while sending response. Writing stopped premature.";
366+
break;
367+
}
349368
transferred += to_transfer;
350369
}
351370
}
@@ -439,10 +458,15 @@ namespace crow
439458
});
440459
}
441460

442-
inline void do_write_sync(std::vector<asio::const_buffer>& buffers)
461+
inline error_code do_write_sync(std::vector<asio::const_buffer>& buffers)
443462
{
444463
error_code ec;
445464
asio::write(adaptor_.socket(), buffers, ec);
465+
if (ec)
466+
{
467+
// CROW_LOG_ERROR << ec << " - happened while sending buffers";
468+
CROW_LOG_DEBUG << this << " from write (sync)(2)";
469+
}
446470

447471
this->res.clear();
448472
this->res_body_copy_.clear();
@@ -455,11 +479,7 @@ namespace crow
455479
this->parser_.clear();
456480
}
457481

458-
if (ec)
459-
{
460-
CROW_LOG_ERROR << ec << " - happened while sending buffers";
461-
CROW_LOG_DEBUG << this << " from write (sync)(2)";
462-
}
482+
return ec;
463483
}
464484

465485
void cancel_deadline_timer()

0 commit comments

Comments
 (0)