[ 
https://issues.apache.org/jira/browse/THRIFT-2975?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14304366#comment-14304366
 ] 

ASF GitHub Bot commented on THRIFT-2975:
----------------------------------------

GitHub user abhinav opened a pull request:

    https://github.com/apache/thrift/pull/370

    THRIFT-2975 Graceful handling of server-side errors in Python

    Change `process_*` functions to handle unexpected exceptions from
    user-supplied handlers by throwing a `TApplicationException(INTERNAL_ERROR)`
    to the client.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/abhinav/thrift THRIFT-2975

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/370.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #370
    
----
commit d1ba19758e40516233378692a244580a6d9dc5ef
Author: Abhinav Gupta <[email protected]>
Date:   2015-02-03T20:52:18Z

    [python] Graceful handling of server-side errors
    
    Changes `process_*` functions to handle unexpected exceptions from
    user-supplied handlers by throwing a `TApplicationException(INTERNAL_ERROR)`
    to the client.

----


> Graceful handing of unexpected errors
> -------------------------------------
>
>                 Key: THRIFT-2975
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2975
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Python - Compiler
>    Affects Versions: 0.9.2
>            Reporter: Abhinav Gupta
>
> Currently, the Python compiler generate {{Processor.process_*}} methods that 
> look something like,
> {code}
> def process_myMethod(...):
>   myArg = ...
>   try:
>     result.success = self._handler.myMethod(myArg)
>   except ExpectedException, e:
>     result.exc = ...
> {code}
> If {{handler.myMethod}} throws an exception that was not defined in the 
> service interface (due to a bug, for example), the client connection is 
> terminated without any extra information being sent down. This is unideal 
> because the client dos not know whether the issue was a networking error or a 
> server-side problem.
> A possibly better behavior would be,
> {code}
> def process_myMethod(...):
>   myArg = ...
>   try:
>     self._handler.myMethod(myArg)
>   except ExpectedException, e:
>     ...
>   except Exception:
>     exc = TApplicationException(INTERNAL_ERROR)
>     # write exc to output protocol as an exception
> {code}
> The generated clients already expect {{TApplicationException}} in the 
> response and know how to parse and handle them, so this won't require any 
> change on the client side.
> Note that this will leave the connection open for further requests. My 
> understanding is that there are some security concerns around that. So 
> perhaps the behavior could be that {{process_*}} throws a 
> {{TApplicationException}} and {{Processor.process}} catches it, sends it to 
> the client and terminates the connection.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to