Skip to content

Commit 985fd8c

Browse files
authored
Retry API connection in more cases (#331)
- if we exceed the heartbeat timeout but were already connected, we try again (probably network issues?) - if the API has problems, we will retry in intervals of 10-30 minutes
1 parent fb1484c commit 985fd8c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/kz/global/kz_global.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,17 @@ void KZGlobalService::OnWebSocketMessage(const ix::WebSocketMessagePtr &message)
423423
}
424424
break;
425425

426+
case 1008 /* POLICY VIOLATION */:
427+
{
428+
if (KZGlobalService::state.load() == KZGlobalService::State::HandshakeCompleted
429+
&& message->closeInfo.reason.find("heartbeat") != message->closeInfo.reason.size())
430+
{
431+
KZGlobalService::socket->enableAutomaticReconnection();
432+
KZGlobalService::state.store(KZGlobalService::State::DisconnectedButWorthRetrying);
433+
}
434+
}
435+
break;
436+
426437
default:
427438
{
428439
KZGlobalService::socket->disableAutomaticReconnection();
@@ -459,8 +470,10 @@ void KZGlobalService::OnWebSocketMessage(const ix::WebSocketMessagePtr &message)
459470
case 502:
460471
{
461472
META_CONPRINTF("[KZ::Global] API encountered an internal error\n");
462-
KZGlobalService::socket->disableAutomaticReconnection();
463-
KZGlobalService::state.store(KZGlobalService::State::Disconnected);
473+
KZGlobalService::socket->enableAutomaticReconnection();
474+
KZGlobalService::socket->setMinWaitBetweenReconnectionRetries(10 * 60'000 /* ms */);
475+
KZGlobalService::socket->setMaxWaitBetweenReconnectionRetries(30 * 60'000 /* ms */);
476+
KZGlobalService::state.store(KZGlobalService::State::DisconnectedButWorthRetrying);
464477
}
465478
break;
466479

0 commit comments

Comments
 (0)