How Does grpcio - Python handle interceptor exceptions?

471 views
Skip to first unread message

Jun Hyung Shin

unread,
Nov 18, 2021, 6:17:29 AM11/18/21
to grpc.io
If a exception happened at one of trailing interceptors

gRPC somehow replace the response with _FailureOutcome
and makes the interceptor has no problem.

So I thought there should be some where wrapping
user overrided method with try / except

and when Exception is raised, replace the response with _FailureOutcome

pseudocode

```python
# somewhere deep in grpcio ...

def run_user_defined_interceptor_method(response):
try :
response = intercept_unary_unary( continuation, client_call_details, request   )
except Exception as e:
response = _FailureOutcome(exception = e)
return response
```
so even I run into a exception in interceptor and interceptor handle well
eventually at client code, not handling error bump into exception

I'm quite sure about how it works because
codes under where exception happened doesn't run

I can't find where those wrappings are happened like pseudocode

class that implements abstract method "intercept_unary_unary"
has no more than a abstract code,

so as I said, there should be something more under grpcio

...

This design was impressive because
it looked like mocking kind of Javascript's then(), catch()
and async pattern, but not actually  async (in a way of propagating error) 
and makes it easy to trace errors 

most of all,  as a client side, it looks like real network connection even it was problem from interceptor

and as for enterprise level, it looked quite safe from unexpected errors

I have no experience with using gRPC as enterprise level,
just got interested at gRPC, I'm senior freshman now.

Richard Belleville

unread,
Dec 1, 2021, 2:28:55 PM12/1/21
to grpc.io
I think this is the code block you're wondering about. There's one for each of the four arities.

I hope that answers your question. Let me know if you want any more info.

Reply all
Reply to author
Forward
0 new messages