Fix data race in WebSocket where _url is accessed without protection in setThreadName

Also fix with url usage + docker container uses fedora and works with tsan
This commit is contained in:
Benjamin Sergeant
2019-04-25 16:07:49 -07:00
parent d37ed300e2
commit 9367a1feff
7 changed files with 34 additions and 45 deletions

View File

@ -205,20 +205,18 @@ namespace ix
}
void CobraConnection::configure(const std::string& appkey,
const std::string& endpoint,
const std::string& rolename,
const std::string& rolesecret,
WebSocketPerMessageDeflateOptions webSocketPerMessageDeflateOptions)
const std::string& endpoint,
const std::string& rolename,
const std::string& rolesecret,
const WebSocketPerMessageDeflateOptions& webSocketPerMessageDeflateOptions)
{
_appkey = appkey;
_endpoint = endpoint;
_role_name = rolename;
_role_secret = rolesecret;
_roleName = rolename;
_roleSecret = rolesecret;
std::stringstream ss;
ss << _endpoint;
ss << endpoint;
ss << "/v2?appkey=";
ss << _appkey;
ss << appkey;
std::string url = ss.str();
_webSocket->setUrl(url);
@ -242,7 +240,7 @@ namespace ix
bool CobraConnection::sendHandshakeMessage()
{
Json::Value data;
data["role"] = _role_name;
data["role"] = _roleName;
Json::Value body;
body["data"] = data;
@ -304,7 +302,7 @@ namespace ix
bool CobraConnection::sendAuthMessage(const std::string& nonce)
{
Json::Value credentials;
credentials["hash"] = hmac(nonce, _role_secret);
credentials["hash"] = hmac(nonce, _roleSecret);
Json::Value body;
body["credentials"] = credentials;

View File

@ -56,7 +56,7 @@ namespace ix
const std::string& endpoint,
const std::string& rolename,
const std::string& rolesecret,
WebSocketPerMessageDeflateOptions webSocketPerMessageDeflateOptions);
const WebSocketPerMessageDeflateOptions& webSocketPerMessageDeflateOptions);
static void setTrafficTrackerCallback(const TrafficTrackerCallback& callback);
@ -135,10 +135,8 @@ namespace ix
std::unique_ptr<WebSocket> _webSocket;
/// Configuration data
std::string _appkey;
std::string _endpoint;
std::string _role_name;
std::string _role_secret;
std::string _roleName;
std::string _roleSecret;
std::atomic<CobraConnectionPublishMode> _publishMode;
// Can be set on control+background thread, protecting with an atomic