Coder Social home page Coder Social logo

Comments (10)

ethe avatar ethe commented on August 22, 2024

Generally, "Missing result" exception means you do not use the same thrift IDL in both server and client side, please check it. If you still got this exception, you can post a sample here, I will try to reproduce it.

from thriftpy2.

zyi1992 avatar zyi1992 commented on August 22, 2024

The code is very simple function for return a string, but the problem was i can't reproduce it , In my project , this exception happened very rare.

from thriftpy2.

ethe avatar ethe commented on August 22, 2024

I can not check or fix an irreproducible error.

from thriftpy2.

zyi1992 avatar zyi1992 commented on August 22, 2024

Sorry for that, Hope anyone else bear this problem can provide some suggest.

from thriftpy2.

wooparadog avatar wooparadog commented on August 22, 2024

@zyi1992 Can you tell us which client you are using? The client in thriftpy is quite low level, and doesn't handle many edge cases.

from thriftpy2.

zyi1992 avatar zyi1992 commented on August 22, 2024
from thriftpy.rpc import make_client
client = make_client(service, host, port, timeout=timeout)

This was the client define code.

from thriftpy2.

wooparadog avatar wooparadog commented on August 22, 2024

@zyi1992 , @ethe has came up with a possible explanation yesterday. The problem is that make_client in thriftpy doesn't handle timeout by itself, so weird things might happen if a timeout occurs.

Background: The client produced by make_client is basically based on a single connection, and won't handle any exceptions during communication(according to the original python-thrift).

What happens:

  1. First rpc call made to server
  2. Server hangs for more than timeout set by client.
  3. Client raise socket.timeout error. but the connection is still open
  4. Server finishes the first rpc response and send it to client. Data will be stored in client's buffer.
  5. Client makes a second request, and try to get its response.
  6. Client reads from buffer which contains response for the first one.
  7. Raise weird protocol exceptions(including missing result)

The fix is to do proper connection management, you can write it according to your scenarios. We are using thrift_connector in that matter.

from thriftpy2.

zyi1992 avatar zyi1992 commented on August 22, 2024

Thanks for you reply, I will have a try on thrift_connector. It seems like thrift_connector didn't deal with thriftpy server restart exception, When use thriftpy with gunicron_thrift, the server side restart will cause client side to raise a TTransportException excetion, is there a best practice for auto reconnection without restart exception.

from thriftpy2.

wooparadog avatar wooparadog commented on August 22, 2024

@zyi1992 Actually, thrift_connector does handle this situation by preventing it rather than raising a TTransportException.

Before every rpc, thrift_connector will try to validate the connection by calling ping thrift method, then the actual rpc. If any error occurs during ping, it'll simply create a new connection for this rpc.

Code: https://github.com/Thriftpy/thrift_connector/blob/master/thrift_connector/connection_pool.py#L82

There are many practices out there:

  1. Validating connection before every call. (Default in thrift_connector. In our server implementation, server will raise a ServerShutdownException in ping if server is gracefully shutting down.)
  2. Maintaining a thread to make sure all connections in connection pool are valid. (Also implemented in thrift_connector, but for performance issues, we don't use it)
  3. Use event polling to discover closed connections and process them.

The best method is 3, but we havn't got time to dig deeper than doing a POC.

from thriftpy2.

zyi1992 avatar zyi1992 commented on August 22, 2024

Thanks for you explain.

from thriftpy2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.