pombreda / gevent

Automatically exported from code.google.com/p/gevent
0 stars 0 forks source link

Different greenlets closing the wrong socket #117

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Download bitHopper github.com/c00w/bitHopper
2. Point about 400Mh/s at it
3. Watch gevent explode.

What is the expected output? What do you see instead?
It should run. Instead I see
Traceback (most recent call last):
File "/home/clr/bitHopper/work.py", line 116, in jsonrpc_call
resp, content = http.request( url, 'POST', headers=header, body=request)
File "/home/clr/bitHopper/httplib20_7_1/init.py", line 1437, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, 
body, headers, redirections, cachekey)
File "/home/clr/bitHopper/httplib20_7_1/init.py", line 1188, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, 
headers)
File "/home/clr/bitHopper/httplib20_7_1/init.py", line 1124, in _conn_request
conn.request(method, request_uri, body, headers)
File "/usr/lib/python2.7/httplib.py", line 955, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 989, in _send_request
self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 951, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 811, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 787, in send
self.sock.sendall(data)
File 
"/usr/local/lib/python2.7/dist-packages/gevent-1.0dev-py2.7-linux-x86_64.egg/gev
ent/socket.py", line 474, in sendall
data_sent += self.send(_get_memory(data, data_sent), flags, timeout=timeleft)

File 
"/usr/local/lib/python2.7/dist-packages/gevent-1.0dev-py2.7-linux-x86_64.egg/gev
ent/socket.py", line 446, in send
self._wait(self._write_event)
File 
"/usr/local/lib/python2.7/dist-packages/gevent-1.0dev-py2.7-linux-x86_64.egg/gev
ent/socket.py", line 283, in _wait
assert watcher.callback is None, 'This socket is already used by another 
greenlet: %r' % (watcher.callback, )
AssertionError: This socket is already used by another greenlet: 
Traceback (most recent call last):
File "/home/clr/bitHopper/work.py", line 116, in jsonrpc_call
resp, content = http.request( url, 'POST', headers=header, body=request)
File "/home/clr/bitHopper/httplib20_7_1/init.py", line 1437, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, 
body, headers, redirections, cachekey)
File "/home/clr/bitHopper/httplib20_7_1/init.py", line 1188, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, 
headers)
File "/home/clr/bitHopper/httplib20_7_1/init.py", line 1154, in _conn_request
conn.connect()
File "/home/clr/bitHopper/httplib20_7_1/init.py", line 796, in connect
raise socket.error, msg
error: [Errno 9] File descriptor was closed in another greenlet

What version of the gevent are you using?
1.0tip
On what operating system?
ubuntu 11.10
On what Python?
2.7
Please provide any additional information below.

Original issue reported on code.google.com by daH4...@gmail.com on 6 Feb 2012 at 1:37

GoogleCodeExporter commented 9 years ago
The exception means that while connect() was in progress another greenlet 
called close() on the same socket.

Just don't do that (or do but expect the exception) and you'll be fine.

Original comment by Denis.Bi...@gmail.com on 6 Feb 2012 at 3:57

GoogleCodeExporter commented 9 years ago
I'm pretty sure something is going wrong on the gevent end. None of these 
errors appear when using 0.13.6. I'm using a bog standard networking library 
and connections are only closed once.

Original comment by daH4...@gmail.com on 6 Feb 2012 at 2:20

GoogleCodeExporter commented 9 years ago
> bog standard networking library

this is irrelevant. The fact that it's standard does not mean it's thread-safe 
or greenlet-safe. In fact, it almost always not.

> and connections are only closed once.

this is also irrelevant.

What's relevant is whether or not you're using the same socket in multiple 
greenlets at the same time. The errors clearly say that you do just that.

From grepping your code you do a lot of spawn()s. Are you sure none of those 
spawned greenlet share a socket and call methods on it?

Original comment by Denis.Bi...@gmail.com on 6 Feb 2012 at 2:43

GoogleCodeExporter commented 9 years ago
I'm rewriting the code to make sure that each socket is only closed by one 
greenlet. I'll be sure after that and if the error still appears I'll update 
you.

Original comment by daH4...@gmail.com on 6 Feb 2012 at 2:46

GoogleCodeExporter commented 9 years ago
Migrated to http://github.com/SiteSupport/gevent/issues/117

Original comment by Denis.Bi...@gmail.com on 14 Sep 2012 at 10:52