twitch: fix race in connect establishing multiple connections

This commit is contained in:
Adam
2019-03-20 09:13:52 -04:00
parent be1a7953fa
commit 9249129383

View File

@@ -96,7 +96,7 @@ public class TwitchPlugin extends Plugin implements TwitchListener, ChatboxInput
return configManager.getConfig(TwitchConfig.class); return configManager.getConfig(TwitchConfig.class);
} }
private void connect() private synchronized void connect()
{ {
if (twitchConfig.username() != null if (twitchConfig.username() != null
&& twitchConfig.oauthToken() != null && twitchConfig.oauthToken() != null
@@ -108,6 +108,13 @@ public class TwitchPlugin extends Plugin implements TwitchListener, ChatboxInput
channel = "#" + channel; channel = "#" + channel;
} }
log.debug("Connecting to Twitch as {}", twitchConfig.username());
if (twitchIRCClient != null)
{
twitchIRCClient.close();
}
twitchIRCClient = new TwitchIRCClient( twitchIRCClient = new TwitchIRCClient(
this, this,
twitchConfig.username(), twitchConfig.username(),
@@ -145,12 +152,6 @@ public class TwitchPlugin extends Plugin implements TwitchListener, ChatboxInput
return; return;
} }
if (twitchIRCClient != null)
{
twitchIRCClient.close();
twitchIRCClient = null;
}
connect(); connect();
} }