summaryrefslogtreecommitdiff
path: root/logcat
diff options
context:
space:
mode:
authorAaron Vaage <vaage@google.com>2022-07-26 07:43:47 -0700
committerAaron Vaage <vaage@google.com>2022-07-26 20:58:05 +0000
commitcceba1196a3e3af57c2eb13e527e159ed2f1fe4f (patch)
treecfb41ae13a67d72de540d7046fd14fd89430260b /logcat
parent33cf6a60468300dbf7066ffafc0b101eacc36f07 (diff)
downloadidea-cceba1196a3e3af57c2eb13e527e159ed2f1fe4f.tar.gz
Fix race condition in logcat panel
There was a race condition in the logcat where we report having a device before we have started the service. While this did not present any problems in production, the race condition allowed for failures in our tests. See ag/19419228 failures for an example of an unrelated change seeing test failures. The failures could be reproduced by running connectDevice_readLogcat on its own (fail) and running it as part of the class (pass). Change-Id: I98844228a3ce94a3a082c33db44c18c10c9620b5
Diffstat (limited to 'logcat')
-rw-r--r--logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt9
1 files changed, 6 insertions, 3 deletions
diff --git a/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt b/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt
index a009c769739..66013f84185 100644
--- a/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt
+++ b/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt
@@ -548,10 +548,13 @@ internal class LogcatMainPanel(
document.setText("")
}
messageBacklog.get().clear()
- connectedDevice.set(device)
+
return coroutineScope.launch(Dispatchers.IO) {
- logcatService.readLogcat(device).collect {
- processMessages(it)
+ logcatService.readLogcat(device).also {
+ // Set the device after we start the service so that the service will be running when we
+ // are reporting an active device.
+ connectedDevice.set(device)
+ it.collect { message -> processMessages(message) }
}
}
}