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
10 changes: 10 additions & 0 deletions LibCarla/source/carla/streaming/detail/tcp/ServerSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ namespace tcp {
}

void ServerSession::CloseNow(boost::system::error_code ec) {
// Guard against double-close. CloseNow() can be reached more than once for
// the same session: the deadline timer firing, an async read/write
// completing with an error, and an explicit Close() can all race. Without
// this guard the session invokes _on_closed twice, which calls
// DisconnectSession twice on the stream state, tripping the DEBUG_ASSERT in
// MultiStreamState::DisconnectSession (and corrupting session bookkeeping
// in release builds).
if (_is_closed.exchange(true)) {
return;
}
_deadline.cancel();
if (!ec)
{
Expand Down
4 changes: 4 additions & 0 deletions LibCarla/source/carla/streaming/detail/tcp/ServerSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# pragma clang diagnostic pop
#endif

#include <atomic>

namespace carla {
namespace streaming {
namespace detail {
Expand Down Expand Up @@ -81,6 +83,8 @@ namespace tcp {
callback_function_type _on_closed;

bool _is_writing = false;

std::atomic_bool _is_closed{false};
};

} // namespace tcp
Expand Down
Loading