Skip to content

Commit

Permalink
core: Catch uncaught exceptions in ServerImpl
Browse files Browse the repository at this point in the history
A cleanup regarding grpc#6162
  • Loading branch information
anarsultanov authored and dfawley committed Jan 15, 2021
1 parent 27073bd commit f0665f0
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions core/src/main/java/io/grpc/internal/ServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,10 @@ private void runInternal() {
return;
}
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 @@ -783,12 +779,9 @@ public void runInContext() {
PerfMark.linkIn(link);
try {
getListener().messagesAvailable(producer);
} catch (RuntimeException e) {
internalClose(e);
throw e;
} catch (Error e) {
internalClose(e);
throw e;
} catch (Throwable t) {
internalClose(t);
throw t;
} finally {
PerfMark.stopTask("ServerCallListener(app).messagesAvailable", tag);
}
Expand Down Expand Up @@ -818,12 +811,9 @@ public void runInContext() {
PerfMark.linkIn(link);
try {
getListener().halfClosed();
} catch (RuntimeException e) {
internalClose(e);
throw e;
} catch (Error e) {
internalClose(e);
throw e;
} catch (Throwable t) {
internalClose(t);
throw t;
} finally {
PerfMark.stopTask("ServerCallListener(app).halfClosed", tag);
}
Expand Down Expand Up @@ -892,12 +882,9 @@ public void runInContext() {
PerfMark.linkIn(link);
try {
getListener().onReady();
} catch (RuntimeException e) {
internalClose(e);
throw e;
} catch (Error e) {
internalClose(e);
throw e;
} catch (Throwable t) {
internalClose(t);
throw t;
} finally {
PerfMark.stopTask("ServerCallListener(app).onReady", tag);
}
Expand Down

0 comments on commit f0665f0

Please sign in to comment.