question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught exceptions in server

See original GitHub issue

Please answer these questions before submitting your issue.

What version of gRPC are you using?

1.23.0

What did you expect to see?

Error response after uncaught exception

Refer to the following file/line number: https://github.com/grpc/grpc-java/blob/ba0fd84d79d66f46b4492043c62ecb0fcf85ead2/core/src/main/java/io/grpc/internal/ServerImpl.java#L558

You can see that Exception types that are not subclasses of Error or RuntimeException (known as “checked exceptions”) are not caught here.

Uncaught exceptions result in no response being sent to the client (but the connection remains open) and thus, from the clients perspective, the RPC call hangs indefinitely.

All exceptions should be caught here, not just runtime exceptions and errors.

“Checked” exceptions can be thrown from code that does not declare it in the signature by several means. One example is here: https://stackoverflow.com/questions/15496/hidden-features-of-java/2131355#2131355

Another example is from any kotlin code that calls a java function that throws a checked exception.

NOTE: it looks like the same problem exists in multiple places in this file. The line number I linked is the specific one that I hit in the wild.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
tonicsoftcommented, Sep 24, 2019

fwiw, here’s an example of “sneaky throws” in the wild that I discovered today while doing something completely unrelated. I believe it’s more evidence that GRPC should not be opinionated on this matter and should simply handle all Throwables, as the fact of the matter is that this is a feature of the JVM that people use, wisely or unwisely, Kotlin or no Kotlin:

https://github.com/testcontainers/testcontainers-java/blob/master/core/src/main/java/org/testcontainers/containers/PortForwardingContainer.java https://projectlombok.org/features/SneakyThrows

1reaction
tonicsoftcommented, Sep 19, 2019

@ejona86 here’s the new workaround, which has similar behaviour and is hopefully now safe:

class GlobalGrpcExceptionHandler : ServerInterceptor {
    override fun <ReqT : Any?, RespT : Any?> interceptCall(call: ServerCall<ReqT, RespT>?, headers: Metadata?, next: ServerCallHandler<ReqT, RespT>?): ServerCall.Listener<ReqT> {
        val delegate = next?.startCall(call, headers)
        return object : ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT>(delegate) {
            override fun onHalfClose() {
                try {
                    super.onHalfClose()
                } catch (e: Exception) {
                    throw RuntimeException(e)
                }

            }
        }
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught Exceptions in Node.js - George Ornbo
The problem of uncaught exceptions. Because Node.js runs on a single process uncaught exceptions are an issue to be aware of when developing ......
Read more >
node.js - Which file does the code to handle uncaught ...
Which file does the code to handle uncaught exceptions go in Node server? ... process.on('uncaughtException', err => { console.error('There was an ...
Read more >
What is an Unhandled Exception, and How to Catch All C# ...
An exception is a known type of error. An unhandled exception occurs when the application code does not properly handle exceptions.
Read more >
Processing Unhandled Exceptions (C#) - Microsoft Learn
Because control was transferred, the custom error page has access to the unhandled exception information via Server.GetLastError and can notify ...
Read more >
As A Node.js Novice, I Don't Understand Why Uncaught ...
I think part of my confusion may come from my ColdFusion programming background. In ColdFusion, uncaught exceptions can happen at any time and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found