jgarzik / python-bitcoinrpc

Python interface to bitcoin's JSON-RPC API
GNU Lesser General Public License v2.1
642 stars 307 forks source link

socket.timeout: timed out #33

Open robertsdotpm opened 10 years ago

robertsdotpm commented 10 years ago

Under Python 3.3, Ubuntu 14.04 I use the following code: from bitcoinrpc.authproxy import AuthServiceProxy x = AuthServiceProxy("....") x.rpc_calls(...)

The Bitcoin RPC version I'm using is from the latest master branch.

Anyway, here is my observation: After making at least one successful RPC call the library will randomly throw a timeout exception that looks like this: Original exception was: Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.3/dist-packages/bitcoinrpc/authproxy.py", line 116, in call response = self._get_response() File "/usr/local/lib/python3.3/dist-packages/bitcoinrpc/authproxy.py", line 138, in _get_response http_response = self.__conn.getresponse() File "/usr/lib/python3.3/http/client.py", line 1147, in getresponse response.begin() File "/usr/lib/python3.3/http/client.py", line 358, in begin version, status, reason = self._read_status() File "/usr/lib/python3.3/http/client.py", line 320, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.3/socket.py", line 297, in readinto return self._sock.recv_into(b) socket.timeout: timed out

I'm just wondering what the reason is for the timeout. It seems my Bitcoind daemon is never actually down. After the timeout occurs I can't issue any more RPC commands without the same exception but if I immediately reconnect with x = AuthServiceProxy("....") and issue the same failed RPC call it ends up working.

An obvious fix is to use a wrapper, but I'm wondering if it's a problem with this library or what reasons there are for this error.

I have confirmed the bug exists under multiple Python versions and multiple coind versions (hosted locally and remotely.) The RPC connection doesn't necessarily need to be open for a long time before the timeout occurs and there doesn't seem to be any pattern to the error.

robertsdotpm commented 10 years ago

Unless it really is that the connection has been open too long. I haven't exactly tried to time things.

ShawnKimble commented 8 years ago

I see the same error, Ubuntu 15.10, Python 2.7

Might be related to #txns in memory on the node, causing low memory condition. I feel core doesn't handle memory efficiently.

dzimbeck commented 7 years ago

Redefining Authserviceproxy doesn't work for me. This issue is really driving me crazy.

dzimbeck commented 7 years ago

Okay so if it fails you can reboot the daemon and then like robertsdotpm said and then you say like: Proxy = AuthServiceProxy(url) Then you need to repeat this EVERY time you fail. A single failure will throw it off forever until its called again at least in my experience. Would be nice to see this bug resolved. This is the only workaround I've come up with

mooncoindev commented 7 years ago

@dzimbeck Restarting the daemon is a time/memory expensive way to get around the problem. Instead if you structure your python script to 'fall through' and exit after a set of RPC commands is executed; you can simply set your python to be continually re-executed in a small looping bash script. This way you get around the issue where redefining AuthServiceProxy doesn't wake the connection back up. I don't believe it is the daemon. Check the moonaudit script in my repo.

dzimbeck commented 7 years ago

Thanks yeah I see that I can just try catch and then when it gets disconnected, just redeclare the authproxy. If that doesn't fire it back up your solution works. You are right, no need to restart the daemon.