Fix socket thrashing on disconnect#64
Conversation
| async def close(self): | ||
| self._closed = True | ||
| await self.writer.close() | ||
| self.writer.close() |
There was a problem hiding this comment.
The writer doesn't support awaiting on close()
There was a problem hiding this comment.
| data = await buf.get() | ||
| except Exception: | ||
| logger.exception("message_handler") | ||
| break |
There was a problem hiding this comment.
Even with the break this always seems to get concurrent.futures._base.CancelledError
There was a problem hiding this comment.
ERROR 2019-12-09 14:09:21,866 controller receptor message_handler
Traceback (most recent call last):
File "/c/Users/bsdma/Desktop/ansible/receptor/receptor/receptor.py", line 91, in message_handler
data = await buf.get()
File "/c/Users/bsdma/Desktop/ansible/receptor/receptor/messages/envelope.py", line 157, in get
return await self.q.get()
File "/usr/lib/python3.6/asyncio/queues.py", line 167, in get
yield from getter
concurrent.futures._base.CancelledError
There was a problem hiding this comment.
it also seems to be delayed by a few seconds... I'm guessing we're still awaiting further down?
There was a problem hiding this comment.
If we get a cancellation from the previous await, we should probably just return. Are you saying that the except Exception fails to capture the cancellation?
There was a problem hiding this comment.
That's what it looks like
|
|
||
| async def __anext__(self): | ||
| bytes_ = await self.reader.read(self.chunk_size) | ||
| if not bytes_: |
There was a problem hiding this comment.
I'm not sure if this bit is actually needed but the empty byte seems to fall through if it's not caught at some other point.
The underlying transport doesn't seem to realize the connection has gone away underneath it. This detects the scenario and closes the connection.
8bfde2d to
d7b9196
Compare
| while self.q.qsize() > 0: | ||
| ident = await self.q.get() | ||
| data = await self._get_file(ident, handle_only=True, delete=False) | ||
| # TODO: This will never work, it's not pure json anymore |
There was a problem hiding this comment.
I planned on fixing this in the next bit of work for the buffers.
| data = await buf.get() | ||
| except Exception: | ||
| logger.exception("message_handler") | ||
| break |
There was a problem hiding this comment.
If we get a cancellation from the previous await, we should probably just return. Are you saying that the except Exception fails to capture the cancellation?
The underlying transport doesn't seem to realize the connection has
gone away underneath it. This detects the scenario and closes the connection.