Search code examples
network-programmingthrift

how to specify reuseaddr socket option on thrift client?


I am working with thrift-python now. And After I checked source code of that, I found that on server end, thrift setsockopt(reuseaddr, 1) by default. It's helpful for Ctrl + C and restart server to debug.

But now I have too many clients at localhost, they use short connections to communicate with server. And when they close connecitons, those random ports are exactly in TIME_WAIT status! so they could cover ports which I want to run another thrift server on it. So, How could I specify REUSEADDR option on thrift client end?


Solution

  • I have figure out some detail about thrift,

    1. on the server side, the REUSEADDR option is set by default;
    2. on the client side, it seems that we couldn't specify that option on underlay TCP connections;
    3. on the client side, we can use long connections instead of short connections to avoid too many TIME_WAIT. To do this, we need call transport.open() just once;
    4. on the server side, we can use TForkingServer instead of ThreadedPoolServer;