Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42e0b7f

Browse files
committed
asyncore: introduce a new 'closed' attribute to make sure that dispatcher gets closed only once.
In different occasions close() might be called more than once, causing problems with already disconnected sockets/dispatchers.
1 parent 2933312 commit 42e0b7f

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

Lib/asyncore.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class dispatcher:
220220

221221
connected = False
222222
accepting = False
223-
closing = False
223+
closed = False
224224
addr = None
225225
ignore_log_types = frozenset(['warning'])
226226

@@ -393,14 +393,16 @@ def recv(self, buffer_size):
393393
raise
394394

395395
def close(self):
396-
self.connected = False
397-
self.accepting = False
398-
self.del_channel()
399-
try:
400-
self.socket.close()
401-
except socket.error as why:
402-
if why.args[0] not in (ENOTCONN, EBADF):
403-
raise
396+
if not self.closed:
397+
self.closed = True
398+
self.connected = False
399+
self.accepting = False
400+
self.del_channel()
401+
try:
402+
self.socket.close()
403+
except socket.error as why:
404+
if why.args[0] not in (ENOTCONN, EBADF):
405+
raise
404406

405407
# cheap inheritance, used to pass all other attribute
406408
# references to the underlying socket object.

0 commit comments

Comments
 (0)