fixed race condition in connSocketWrite

Former-commit-id: d7f01c1f7d1bb2d6e0b004f532f7b98ed968d389
This commit is contained in:
christianEQ 2021-01-26 22:08:07 +00:00
parent 1907c4f6f8
commit 237f3e8524

View File

@ -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;