From 86f6fca7033828f5f11ec4f9c4379d9f50fd9d43 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Fri, 31 Jan 2020 16:25:45 -0800 Subject: [PATCH] (IXCobraConnection) set a ping timeout of 90 seconds. If no pong messages are received as responses to ping for a while, give up and close the connection --- docs/CHANGELOG.md | 4 ++++ ixcobra/ixcobra/IXCobraConnection.cpp | 8 ++++++++ ixwebsocket/IXWebSocketVersion.h | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 75c0a3e8..70baf7a5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All changes to this project will be documented in this file. +## [8.0.5] - 2020-01-31 + +(IXCobraConnection) set a ping timeout of 90 seconds. If no pong messages are received as responses to ping for a while, give up and close the connection + ## [8.0.4] - 2020-01-31 (cobra to sentry) remove noisy logging diff --git a/ixcobra/ixcobra/IXCobraConnection.cpp b/ixcobra/ixcobra/IXCobraConnection.cpp index 21e1f285..4775cefa 100644 --- a/ixcobra/ixcobra/IXCobraConnection.cpp +++ b/ixcobra/ixcobra/IXCobraConnection.cpp @@ -265,7 +265,15 @@ namespace ix _webSocket->setUrl(url); _webSocket->setPerMessageDeflateOptions(webSocketPerMessageDeflateOptions); _webSocket->setTLSOptions(socketTLSOptions); + + // Send a websocket ping every N seconds (N = 30) now + // This should keep the connection open and prevent some load balancers such as + // the Amazon one from shutting it down _webSocket->setPingInterval(kPingIntervalSecs); + + // If we don't receive a pong back, declare loss after 3 * N seconds + // (will be 90s now), and close and restart the connection + _webSocket->setPingTimeout(3 * kPingIntervalSecs); } // diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 7ce5f01a..ec9dce47 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "8.0.4" +#define IX_WEBSOCKET_VERSION "8.0.5"