Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clear pubsub command queue on reconnect #599

Merged
merged 2 commits into from Jul 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -255,8 +255,10 @@ public TwitchPubSub(WebsocketConnection websocketConnection, EventManager eventM
this.connection = new WebsocketConnection(spec -> {
spec.baseUrl(WEB_SOCKET_SERVER);
spec.wsPingPeriod(wsPingPeriod);
spec.onPreConnect(this::onPreConnect);
spec.onConnected(this::onConnected);
spec.onTextMessage(this::onTextMessage);
spec.onPostDisconnect(commandQueue::clear);
spec.taskExecutor(taskExecutor);
spec.proxyConfig(proxyConfig);
if (connectionBackoffStrategy != null)
Expand Down Expand Up @@ -339,10 +341,6 @@ public TwitchPubSub(WebsocketConnection websocketConnection, EventManager eventM
* Connecting to IRC-WS
*/
public void connect() {
// Reset last ping to avoid edge case loop where reconnect occurred after sending PING but before receiving PONG
lastPong = TimeUtils.getCurrentTimeInMillis();
lastPing = lastPong - 4 * 60 * 1000;

connection.connect();
}

Expand All @@ -361,6 +359,12 @@ public void reconnect() {
connection.reconnect();
}

protected void onPreConnect() {
// Reset last ping to avoid edge case loop where reconnect occurred after sending PING but before receiving PONG
lastPong = TimeUtils.getCurrentTimeInMillis();
lastPing = lastPong - 4 * 60 * 1000;
}

protected void onConnected() {
log.info("Connected to Twitch PubSub {}", WEB_SOCKET_SERVER);

Expand Down