Wrap race condition in CancellationException

This commit is contained in:
Mygod
2021-08-22 02:36:30 -04:00
parent fb8538ecbe
commit f50d579fd3

View File

@@ -231,8 +231,12 @@ class RootServer {
* Caller should check for active. * Caller should check for active.
*/ */
private fun sendLocked(command: Parcelable) { private fun sendLocked(command: Parcelable) {
try {
output.writeParcelable(command) output.writeParcelable(command)
output.flush() output.flush()
} catch (e: IOException) {
if (e.isEBADF) throw CancellationException().initCause(e) else throw e
}
Logger.me.d("Sent #$counter: $command") Logger.me.d("Sent #$counter: $command")
counter++ counter++
} }
@@ -300,8 +304,9 @@ class RootServer {
sendLocked(Shutdown()) sendLocked(Shutdown())
output.close() output.close()
process.outputStream.close() process.outputStream.close()
} catch (_: CancellationException) {
} catch (e: IOException) { } catch (e: IOException) {
if (!e.isEBADF) Logger.me.w("send Shutdown failed", e) Logger.me.w("send Shutdown failed", e)
} }
Logger.me.d("Client closed") Logger.me.d("Client closed")
} }