Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

socket.timeout: timed out #204

Closed
imperio-wxm opened this issue May 30, 2016 · 13 comments
Closed

socket.timeout: timed out #204

imperio-wxm opened this issue May 30, 2016 · 13 comments

Comments

@imperio-wxm
Copy link

imperio-wxm commented May 30, 2016

Hi,how can I set timeout in thriftpy?

I whrite like:

with client_context(dd_thrift.DingService, '127.0.0.1', 9090, proto_factory=dd_factory,
    socket_timeout=5000,connect_timeout=5000) as c:

But error:

UserWarning: `timeout` deprecated, use `socket_timeout` and `connect_timeout` instead.
warnings.warn("`timeout` deprecated, use `socket_timeout` and "
..........
..........
File "/usr/local/lib/python2.7/dist-packages/thriftpy/transport/socket.py", line 108, in read
buff = self.sock.recv(sz)
socket.timeout: timed out

Thanks!

@MrKiven
Copy link
Contributor

MrKiven commented May 30, 2016

Of course you can.
It seems like your service down..

@imperio-wxm
Copy link
Author

@MrKiven
I am not sure set timeout in my server or client or both?

@MrKiven
Copy link
Contributor

MrKiven commented May 30, 2016

client

@imperio-wxm
Copy link
Author

@MrKiven

My server is fine,but client set socket_timeout=5000 or 5000+ does not work, it is also default 3000.

When I count 3s, time out error come out.

@MrKiven
Copy link
Contributor

MrKiven commented May 30, 2016

server side default timeout is 3s, @lxyu

@imperio-wxm
Copy link
Author

@MrKiven
When I use param like “timeout”,works!, but I notice warning:

UserWarning: `timeout` deprecated, use `socket_timeout` and `connect_timeout` instead.

timeout really deprecated?

@MrKiven
Copy link
Contributor

MrKiven commented May 30, 2016

yes, will use socket_timeout and connect_timeout, but if you set timeout, it also works

what's your thriftpy version?

@imperio-wxm
Copy link
Author

@MrKiven
thriftpy 0.3.8

@AllanDaemon
Copy link

I having the same problem. I ported my implementation of the Apache Python module. IT was working ok. I made a shell for it (stills using the Apache Python Module), that connects and send requests as client to the server and prints the response. But with Thriftpy after 3 seconds the client connects the connection crashes. I can create a new working connection though. Before the time out, it works fine.

ERROR:thriftpy.server:timed out
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/thriftpy/server.py", line 95, in handle
    self.processor.process(iprot, oprot)
  File "/usr/local/lib/python2.7/dist-packages/thriftpy/thrift.py", line 257, in process
    api, seqid, result, call = self.process_in(iprot)
  File "/usr/local/lib/python2.7/dist-packages/thriftpy/thrift.py", line 212, in process_in
    api, type, seqid = iprot.read_message_begin()
  File "thriftpy/protocol/cybin/cybin.pyx", line 429, in cybin.TCyBinaryProtocol.read_message_begin (thriftpy/protocol/cybin/cybin.c:6312)
  File "thriftpy/protocol/cybin/cybin.pyx", line 60, in cybin.read_i32 (thriftpy/protocol/cybin/cybin.c:1531)
  File "thriftpy/transport/buffered/cybuffered.pyx", line 65, in thriftpy.transport.buffered.cybuffered.TCyBufferedTransport.c_read (thriftpy/transport/buffered/cybuffered.c:1872)
  File "thriftpy/transport/buffered/cybuffered.pyx", line 69, in thriftpy.transport.buffered.cybuffered.TCyBufferedTransport.read_trans (thriftpy/transport/buffered/cybuffered.c:1939)
  File "thriftpy/transport/cybase.pyx", line 61, in thriftpy.transport.cybase.TCyBuffer.read_trans (thriftpy/transport/cybase.c:1463)
  File "/usr/local/lib/python2.7/dist-packages/thriftpy/transport/socket.py", line 111, in read
    buff = self.sock.recv(sz)
timeout: timed out

I believe this is a bug. A there is no reason to a connection close after 3 seconds. Sometimes even network latency is longer than it. And for my example, the shell I made is supposed to receive commands from the user, at any time. Also, the canonical Apache implementation doesn't behave this way.

I installed Thriftpy last night with pip:
Successfully installed cython-0.24 ply-3.8 thriftpy-0.3.8

@AllanDaemon
Copy link

AllanDaemon commented Jun 6, 2016

I changed the default client_timeout in thriftpy/transport/socket.py from 3000 to None and now my server is working as expected, just like Apache implementation.

from:

class TServerSocket(object):
    """Socket implementation for server side."""

    def __init__(self, host=None, port=None, unix_socket=None,
                 socket_family=socket.AF_INET, client_timeout=3000,
                 backlog=128):

to:

class TServerSocket(object):
    """Socket implementation for server side."""

    def __init__(self, host=None, port=None, unix_socket=None,
                 socket_family=socket.AF_INET, client_timeout=None,
                 backlog=128):

I see I have the option to pass the timeout when creating a service manually. But the function make_server in thriftpy/rpc.py uses the default parameter for this. I didn't read all the source to figure out where to fix this. One option is passing explicitly client_timeout=None when creating the TServerSocket in make_server function. But It seems to me that the correct approach is setting the default timeout in the TServerSocket class initialization.

By now, the simpler way to use make_server with canonical behavior is this:

from thriftpy.rpc import make_server
s = make_server(Service, ServiceHandler(), host, port)
s.trans.client_timeout = None
(...)

@AllanDaemon
Copy link

These 2 commits fixed it to me.
AllanDaemon@6a4b118
AllanDaemon@0944247

I running tests and I will write some tests for it latter before I make pull request. Does this solutions sounds ok?

@lxyu lxyu closed this as completed in c22ffdc Aug 26, 2016
@lxyu
Copy link
Contributor

lxyu commented Aug 26, 2016

Sorry for the late reply, the issue is because the client_timeout default set to 3000ms and the setting was not exposed in make_server helper function.

You may now pass the client_timeout=None to force the server side never timeout a client socket.

If it doesn't resolve your issue, feel free to reopen this thread.

@ghost
Copy link

ghost commented Sep 12, 2016

Hello. I have thriftpy version 0.3.9 and collided with bug like @AllanDaemon report. As advised above, I replaced the value of client_timeout to None. And it worked. In this regard, I have a question. Maybe it makes sense to initially set the value to None? Thank you for attention.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants