Skip to content

Commit c035666

Browse files
ikichathestinger
authored andcommitted
Handle gRPC canellation case
there was a crash when onNext() is called 'after' shutdown service in the guest is shut down. it happens really rarely, but for stability, add cancellation status check, and callback for the status. Fix: 398765174 Test: keep calling onNext() and check if there is no exception Change-Id: I4d023647a1c69cc2f6b029fb05724bf98b99f35d
1 parent 3b1afd0 commit c035666

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

android/TerminalApp/java/com/android/virtualization/terminal/DebianServiceImpl.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.android.virtualization.terminal.proto.ReportVmActivePortsRequest
2828
import com.android.virtualization.terminal.proto.ReportVmActivePortsResponse
2929
import com.android.virtualization.terminal.proto.ShutdownQueueOpeningRequest
3030
import com.android.virtualization.terminal.proto.ShutdownRequestItem
31+
import io.grpc.stub.ServerCallStreamObserver
3132
import io.grpc.stub.StreamObserver
3233

3334
internal class DebianServiceImpl(context: Context) : DebianServiceImplBase() {
@@ -79,8 +80,15 @@ internal class DebianServiceImpl(context: Context) : DebianServiceImplBase() {
7980
request: ShutdownQueueOpeningRequest?,
8081
responseObserver: StreamObserver<ShutdownRequestItem?>,
8182
) {
83+
val serverCallStreamObserver = responseObserver as ServerCallStreamObserver<ShutdownRequestItem?>
84+
serverCallStreamObserver.setOnCancelHandler {
85+
shutdownRunnable = null
86+
}
8287
Log.d(TAG, "openShutdownRequestQueue")
8388
shutdownRunnable = Runnable {
89+
if (serverCallStreamObserver.isCancelled()) {
90+
return@Runnable
91+
}
8492
responseObserver.onNext(ShutdownRequestItem.newBuilder().build())
8593
responseObserver.onCompleted()
8694
shutdownRunnable = null

0 commit comments

Comments
 (0)