Skip to content

Commit

Permalink
Merge pull request #1305 from pika/lrb-gh-1286
Browse files Browse the repository at this point in the history
PR 1288 continued
  • Loading branch information
lukebakken committed Jan 30, 2021
2 parents 58e2710 + 37be155 commit 5af6a4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pika/adapters/utils/io_services_utils.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,10 @@ def write(self, data):
assert data, ('_AsyncPlaintextTransport.write(): empty data from user.',
data, self._state)

# pika/pika#1286
# NOTE: Modify code to write data to buffer before setting writer.
# Otherwise a race condition can occur where ioloop executes writer
# while buffer is still empty.
tx_buffer_was_empty = self.get_write_buffer_size() == 0

self._buffer_tx_data(data)
Expand Down Expand Up @@ -1156,6 +1160,10 @@ def write(self, data):
assert data, ('_AsyncSSLTransport.write(): empty data from user.',
data, self._state)

# pika/pika#1286
# NOTE: Modify code to write data to buffer before setting writer.
# Otherwise a race condition can occur where ioloop executes writer
# while buffer is still empty.
tx_buffer_was_empty = self.get_write_buffer_size() == 0

self._buffer_tx_data(data)
Expand Down
7 changes: 5 additions & 2 deletions pika/adapters/utils/selector_ioloop_adapter.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,16 @@ def set_writer(self, fd, on_writable):
else:
if callbacks.writer is None:
assert callbacks.reader is not None
# NOTE: Set the writer func before setting the mask!
# Otherwise a race condition can occur where ioloop tries to
# call writer when it is still None.
callbacks.writer = on_writable
self._loop.update_handler(
fd, self._readable_mask | self._writable_mask)
LOGGER.debug('set_writer(%s, _) updated handler RdWr', fd)
else:
LOGGER.debug('set_writer(%s, _) replacing writer', fd)

callbacks.writer = on_writable
callbacks.writer = on_writable

def remove_writer(self, fd):
"""Implement
Expand Down

0 comments on commit 5af6a4b

Please sign in to comment.