From 3636f18d847f326d338adff4cb2f214608b08298 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sun, 17 Jan 2016 15:44:00 +0100 Subject: [PATCH 1/2] McsInputStream: terminate if error occurred This terminates the input stream when an error occurred and does not wait for the handler thread in the McsService to send the interrupt signal. This hopefully fixes a situation that I had where tear down messages were created in a busy loop because of repeatedly reading -1 from the input (I don't know how it got into the situation as the log was filled with the messages from the tear down). --- .../src/main/java/org/microg/gms/gcm/McsInputStream.java | 1 + 1 file changed, 1 insertion(+) diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/McsInputStream.java b/play-services-core/src/main/java/org/microg/gms/gcm/McsInputStream.java index 6af110171f..17d86f0e76 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/McsInputStream.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/McsInputStream.java @@ -77,6 +77,7 @@ public void run() { mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_INPUT, msg)); } else { mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_TEARDOWN, "null message")); + break; // if input is empty, do not continue looping } } } catch (IOException e) { From 48809464a74fffc5abf027b8e6d434d941c8095e Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sun, 17 Jan 2016 15:56:03 +0100 Subject: [PATCH 2/2] McsService: only send to the output stream if it is alive The output stream handler thread might not be alive, this occurs reproducibly when connecting fails and a tear down is initiated. Messages shouldn't be sent when the output handler thread is not alive (triggers an expection which is catched but logged), this check avoids this unless some special race condition occurs. Dropping the messages shouldn't hurt (they were dropped anyway). --- .../src/main/java/org/microg/gms/gcm/McsService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java index efbbb4b322..96f3752559 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java @@ -323,7 +323,7 @@ private void send(Message message) { private void sendOutputStream(int what, Object obj) { McsOutputStream os = outputStream; - if (os != null) { + if (os != null && os.isAlive()) { Handler outputHandler = os.getHandler(); if (outputHandler != null) outputHandler.sendMessage(outputHandler.obtainMessage(what, obj));