[issue17925] asynchat.async_chat.initiate_send : del deque[0] is not safe

Xavier de Gaye report at bugs.python.org
Thu May 9 21:19:55 CEST 2013


Xavier de Gaye added the comment:

The attached script, test_initiate_send.py, tests initiate_send with
threads, causing duplicate writes and an IndexError. This is the
script output using python on the default branch:

$ python test_initiate_send.py
--- Test: duplicate data sent ---
chat.send('thread data')
chat.send('thread data')

--- Test: IndexError ---
chat.send('thread data')
chat.send('thread data')
Exception in thread Thread-2:
Traceback (most recent call last):
  File "Lib/threading.py", line 644, in _bootstrap_inner
    self.run()
  File "Lib/threading.py", line 601, in run
    self._target(*self._args, **self._kwargs)
  File "test_initiate_send.py", line 25, in <lambda>
    thread = threading.Thread(target=lambda : chat.push('thread data'))
  File "Lib/asynchat.py", line 194, in push
    self.initiate_send()
  File "Lib/asynchat.py", line 254, in initiate_send
    del self.producer_fifo[0]
IndexError: deque index out of range


The script does not fail with Pierrick patch:

$ python test_initiate_send.py
--- Test: duplicate data sent ---
chat.send('main data')
chat.send('thread data')

--- Test: IndexError ---
chat.send('thread data')


The patch misses to also appendleft() 'first' when 'num_sent' is zero,
which may happen on getting EWOULDBLOCK on send().

----------
nosy: +xdegaye
Added file: http://bugs.python.org/file30186/test_initiate_send.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17925>
_______________________________________


More information about the Python-bugs-list mailing list