GeezerVison is showing github.com — Protect websockets_ by mutex by andrew-guz · Pull Request #1136 · CrowCpp/Crow
Conversation
andrew-guz
commented
Jan 23, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
gittiver
gittiver approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
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.
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.
|