From 237f3e8524f3ed38e56d066182be329fd38c7fd2 Mon Sep 17 00:00:00 2001 From: christianEQ Date: Tue, 26 Jan 2021 22:08:07 +0000 Subject: [PATCH] fixed race condition in connSocketWrite Former-commit-id: d7f01c1f7d1bb2d6e0b004f532f7b98ed968d389 --- src/connection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index bd8f83f79..8f7c153d0 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -172,8 +172,8 @@ static int connSocketWrite(connection *conn, const void *data, size_t data_len) /* Don't overwrite the state of a connection that is not already * connected, not to mess with handler callbacks. */ - if (conn->state == CONN_STATE_CONNECTED) - conn->state.store(CONN_STATE_ERROR, std::memory_order_relaxed); + ConnectionState expected = CONN_STATE_CONNECTED; + conn->state.compare_exchange_strong(expected, CONN_STATE_ERROR); } return ret;