Vincent Michel <vxgmic...@gmail.com> added the comment:
I found the culprit: https://github.com/python/cpython/blob/a05bef4f5be1bcd0df63ec0eb88b64fdde593a86/Lib/asyncio/streams.py#L350 The call to `_untrack_reader` is performed too soon. Closing the transport causes `protocol.connection_lost()` to be "called soon" but by the time it is actually executed, the stream reader has been "untracked". Since the protocol doesn't know the stream reader anymore, it has not way to feed it the EOF. The fix attached removes the `_untrack_reader` call and definition altogether. I don't really see the point of this method since one has to wait for `connection_lost` to be executed before untracking the reader, but `connection_lost` already gets rid of the reader reference. With this fix, calling `writer.close` then awaiting `writer.wait_closed` (or awaiting `writer.aclose`) should: - close the transport - schedule `protocol.connection_lost` - wait for the protocol to be closed - run `protocol.connection_lost` - feed the EOF to the reader - set the protocol as closed - get rid of the reader reference in the protocol - return (making aclose causal and safe) - the reader can then be safely garbage collected But maybe I'm missing something about `_untrack_reader`? ---------- keywords: +patch Added file: https://bugs.python.org/file47893/patch-bpo-35065.diff _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35065> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com