GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Protect websockets_ by mutex by andrew-guz · Pull Request #1136 · CrowCpp/Crow

Conversation

@andrew-guz

@andrew-guz andrew-guz commented Jan 23, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

We faced the situation, when std::vector<std::shared_ptr<websocket::connection>> websockets_ will be modified in several threads in case of several simultaneous connections been opened and closed.

To prove this and for future needs, we added ThreadSanitizer support (ENABLE_TSAN flag) and new test (multithreaded_websockets_open_close) that shows this problem:

WARNING: ThreadSanitizer: data race (pid=305193)
  Read of size 8 at 0x7ffd1dd3bb48 by main thread:
    #0 __gnu_cxx::__normal_iterator<std::shared_ptr<crow::websocket::connection>*, std::vector<std::shared_ptr<crow::websocket::connection>, std::allocator<std::shared_ptr<crow::websocket::connection> > > >::__normal_iterator(std::shared_ptr<crow::websocket::connection>* const&) /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/stl_iterator.h:1059 (unittest+0x324e8b) (BuildId: e1fdcc2ba235601f5098b0fb0206a07bdd014f10)
    #1 std::vector<std::shared_ptr<crow::websocket::connection>, std::allocator<std::shared_ptr<crow::websocket::connection> > >::end() /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/stl_vector.h:1019 (unittest+0x324e8b)
    #2 crow::Crow<>::close_websockets() /Crow/include/crow/app.h:623 (unittest+0x324a57) (BuildId: e1fdcc2ba235601f5098b0fb0206a07bdd014f10)
    #3 crow::Crow<>::stop() /Crow/include/crow/app.h:614 (unittest+0x26352e) (BuildId: e1fdcc2ba235601f5098b0fb0206a07bdd014f10)

  Previous write of size 8 at 0x7ffd1dd3bb48 by thread T2:
    #0 std::vector<std::shared_ptr<crow::websocket::connection>, std::allocator<std::shared_ptr<crow::websocket::connection> > >::_M_erase_at_end(std::shared_ptr<crow::websocket::connection>*) /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/stl_vector.h:2240 (unittest+0x62b6fc) (BuildId: e1fdcc2ba235601f5098b0fb0206a07bdd014f10)
    #1 std::vector<std::shared_ptr<crow::websocket::connection>, std::allocator<std::shared_ptr<crow::websocket::connection> > >::_M_erase(__gnu_cxx::__normal_iterator<std::shared_ptr<crow::websocket::connection>*, std::vector<std::shared_ptr<crow::websocket::connection>, std::allocator<std::shared_ptr<crow::websocket::connection> > > >, __gnu_cxx::__normal_iterator<std::shared_ptr<crow::websocket::connection>*, std::vector<std::shared_ptr<crow::websocket::connection>, std::allocator<std::shared_ptr<crow::websocket::connection> > > >) /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/vector.tcc:202 (unittest+0x62b29d) (BuildId: e1fdcc2ba235601f5098b0fb0206a07bdd014f10)
    #2 std::vector<std::shared_ptr<crow::websocket::connection>, std::allocator<std::shared_ptr<crow::websocket::connection> > >::erase(__gnu_cxx::__normal_iterator<std::shared_ptr<crow::websocket::connection> const*, std::vector<std::shared_ptr<crow::websocket::connection>, std::allocator<std::shared_ptr<crow::websocket::connection> > > >, __gnu_cxx::__normal_iterator<std::shared_ptr<crow::websocket::connection> const*, std::vector<std::shared_ptr<crow::websocket::connection>, std::allocator<std::shared_ptr<crow::websocket::connection> > > >) /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/stl_vector.h:1824 (unittest+0x62ad7f) (BuildId: e1fdcc2ba235601f5098b0fb0206a07bdd014f10)
    #3 crow::Crow<>::remove_websocket(std::shared_ptr<crow::websocket::connection>) /Crow/include/crow/app.h:640 (unittest+0x62a908) (BuildId: e1fdcc2ba235601f5098b0fb0206a07bdd014f10)

So, protected websockets_ usage with new mutex.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@andrew-guz
andrew-guz force-pushed the websockets-mutex branch 2 times, most recently from 3f57458 to 483f5cc Compare January 23, 2026 14:24
@andrew-guz
Protect websockets_ by mutex
6e5977f
@andrew-guz
andrew-guz force-pushed the websockets-mutex branch from 6aa8b2e to 6e5977f Compare January 23, 2026 14:39
gittiver
gittiver reviewed Jan 25, 2026
View reviewed changes
Comment thread CMakeLists.txt Resolved

Uh oh!

There was an error while loading. Please reload this page.

@andrew-guz
Additional warning ofr TSAN and Clang
38e6a20
@gittiver gittiver mentioned this pull request Jan 27, 2026
onclose handler is called twice for the same websocket #1138
Closed
gittiver
gittiver approved these changes Feb 3, 2026
View reviewed changes
@gittiver
gittiver merged commit 773faaa into CrowCpp:master Feb 3, 2026
36 of 41 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@BrewTestBot BrewTestBot mentioned this pull request Feb 12, 2026
crow: add livecheck Homebrew/homebrew-core#267086
Merged
@BrewTestBot BrewTestBot mentioned this pull request Feb 19, 2026
crow 1.3.1 Homebrew/homebrew-core#268347
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gittiver gittiver gittiver approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@andrew-guz @gittiver
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.