homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: asyncore should handle also ECONNABORTED in recv
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: josiahcarlson Nosy List: giampaolo.rodola, josiahcarlson
Priority: normal Keywords: patch

Created on 2007年06月12日 21:10 by giampaolo.rodola, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Messages (8)
msg52759 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2007年06月12日 21:10
asyncore should handle also ECONNABORTED in recv in which case handle_close must be called.
The two programs in attachment, an asyncore based echo-server and a simple client application terminating after having sent some data, shows how the server raises an ECONNABORTED exception.
Note that the exception does not occur if server responds immediatly so I used a time.sleep(1) statement to let internal socket perform send() on the remote 'dead' peer.
Having said that it's probable that ECONNABORTED should be handled also in send method.
Hope this helps.
msg52760 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2007年06月12日 21:13
client
======
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 21))
s.send("sumthin")
server
======
import asyncore, asynchat
import socket
import time
class Handler(asynchat.async_chat):
 def __init__(self, server, sock, addr):
 asynchat.async_chat.__init__(self, sock)
 self.set_terminator("\n") 
 self.data = ""
 self.respond("Hey there!\r\n")
 def respond(self, data):
 print "->" + data
 time.sleep(1)
 self.push(data)
 def collect_incoming_data(self, data):
 print "<-" + data
 self.data = self.data + data
 def found_terminator(self):
 self.respond(self.data)
 self.data = ''
 def handle_close(self):
 remote_ip, remote_port = self.socket.getpeername()
 print "%s:%s disconnected" %(remote_ip, remote_port)
 self.close()
 def handle_error(self):
 raise
 
class Server(asyncore.dispatcher):
 def __init__(self, address):
 asyncore.dispatcher.__init__(self)
 self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
 self.bind(address)
 self.listen(5)
 def handle_accept(self):
 conn, addr = self.accept()
 Handler(self, conn, addr)
address = ('', 21)
Server(address)
print "server ready."
asyncore.loop()
proposed patch
==============
--- line 55
- from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \
- ENOTCONN, ESHUTDOWN, EINTR, EISCONN, errorcode
+ from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \
+ ENOTCONN, ESHUTDOWN, EINTR, EISCONN, ECONNABORTED, errorcode
--- line 329
 def send(self, data):
 try:
 result = self.socket.send(data)
 return result
 except socket.error, why:
 if why[0] == EWOULDBLOCK:
 return 0
+ elif why[0] == ECONNABORTED:
+ self.handle_close()
+ return 0
 else:
 raise
 return 0
--- line 340
 def recv(self, buffer_size):
 try:
 data = self.socket.recv(buffer_size)
 if not data:
 # a closed connection is indicated by signaling
 # a read condition, and having recv() return 0.
 self.handle_close()
 return ''
 else:
 return data
 except socket.error, why:
 # winsock sometimes throws ENOTCONN
- if why[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN]:
+ if why[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED]:
 self.handle_close()
 return ''
 else:
 raise
msg52761 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2007年06月13日 00:40
Please see python.org/sf/1736190 for a patch that includes this particular bugfixe to asyncore, among others.
msg52762 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2007年06月13日 19:03
Hi, I've seen your patch but it seems to me that it doesn't include ECONNABORTED handling for send method.
msg52763 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2007年06月13日 21:13
Re-read the patch. In particular...
@@ -333,9 +349,11 @@
 except socket.error, why:
 if why[0] == EWOULDBLOCK:
 return 0
+ elif why[0] in (ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED):
+ self.handle_close()
+ return 0
That is added handling for all four potential errors in send.
msg52764 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2007年06月13日 21:58
You're right, sorry.
msg69216 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2008年07月03日 18:01
Fixed in trunk, will be fixed in 3.0 this weekend.
msg69369 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2008年07月07日 04:28
Fixed in 3.0 .
History
Date User Action Args
2022年04月11日 14:56:24adminsetgithub: 45087
2008年07月07日 04:29:18josiahcarlsonsetstatus: open -> closed
resolution: fixed
messages: + msg69369
2008年07月03日 18:01:25josiahcarlsonsetmessages: + msg69216
2007年06月12日 21:10:35giampaolo.rodolacreate

AltStyle によって変換されたページ (->オリジナル) /