Skip to content

Commit 0f54b81

Browse files
committed
Synchronize access so only 1 thread is accessesing event-stream + restarting
1 parent abb962d commit 0f54b81

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/AndroidClient/client/src/main/java/net/servicestack/client/sse/ServerEventsClient.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,17 +554,26 @@ public EventStream(ServerEventsClient client) {
554554
@Override
555555
public void run() {
556556
try {
557+
if (running.get())
558+
return;
559+
running.set(true);
560+
557561
URL streamUri = new URL(client.getEventStreamUri());
558562
HttpURLConnection req = (HttpURLConnection) streamUri.openConnection();
559563

560564
InputStream is = new BufferedInputStream(req.getInputStream());
561565
errorsCount.set(0);
562566
readStream(is);
563-
} catch (IOException e) {
567+
568+
running.set(false);
569+
} catch (Exception e) {
564570
Log.e("Error reading from event-stream, continuous errors: " + errorsCount.incrementAndGet(), e);
565571
Log.e(Utils.getStackTrace(e));
572+
running.set(false);
566573
} finally {
567-
client.restart();
574+
if (!running.get()){
575+
client.restart();
576+
}
568577
}
569578
}
570579

0 commit comments

Comments
 (0)