Skip to content

Commit

Permalink
core: Catch uncaught exceptions in ServerImpl
Browse files Browse the repository at this point in the history
Fixes grpc#6162
  • Loading branch information
anarsultanov committed Sep 19, 2019
1 parent 19b0916 commit c65f705
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions core/src/main/java/io/grpc/internal/ServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public final class ServerImpl extends io.grpc.Server implements InternalInstrume
* Construct a server.
*
* @param builder builder with configuration for server
* @param transportServer transport server that will create new incoming transports
* @param transportServers transport server that will create new incoming transports
* @param rootContext context that callbacks for new RPCs should be derived from
*/
ServerImpl(
Expand Down Expand Up @@ -555,14 +555,10 @@ private void runInternal() {
}
listener =
startCall(stream, methodName, method, headers, context, statsTraceCtx, tag);
} catch (RuntimeException e) {
stream.close(Status.fromThrowable(e), new Metadata());
} catch (Throwable t) {
stream.close(Status.fromThrowable(t), new Metadata());
context.cancel(null);
throw e;
} catch (Error e) {
stream.close(Status.fromThrowable(e), new Metadata());
context.cancel(null);
throw e;
throw t;
} finally {
jumpListener.setListener(listener);
}
Expand Down Expand Up @@ -777,12 +773,9 @@ public void runInContext() {
PerfMark.linkIn(link);
try {
getListener().messagesAvailable(producer);
} catch (RuntimeException e) {
internalClose();
throw e;
} catch (Error e) {
} catch (Throwable t) {
internalClose();
throw e;
throw t;
} finally {
PerfMark.stopTask("ServerCallListener(app).messagesAvailable", tag);
}
Expand Down Expand Up @@ -812,12 +805,9 @@ public void runInContext() {
PerfMark.linkIn(link);
try {
getListener().halfClosed();
} catch (RuntimeException e) {
} catch (Throwable t) {
internalClose();
throw e;
} catch (Error e) {
internalClose();
throw e;
throw t;
} finally {
PerfMark.stopTask("ServerCallListener(app).halfClosed", tag);
}
Expand Down Expand Up @@ -886,12 +876,9 @@ public void runInContext() {
PerfMark.linkIn(link);
try {
getListener().onReady();
} catch (RuntimeException e) {
internalClose();
throw e;
} catch (Error e) {
} catch (Throwable t) {
internalClose();
throw e;
throw t;
} finally {
PerfMark.stopTask("ServerCallListener(app).onReady", tag);
}
Expand Down

0 comments on commit c65f705

Please sign in to comment.