This is a PR to fix#202. As the issue indicates, the error is:
File "[...]/hypercorn/asyncio/tcp_server.py", line 119, in _close
await self.writer.wait_closed()
File "/usr/lib/python3.12/asyncio/streams.py", line 364, in wait_closed
await self._protocol._get_close_waiter(self)
TimeoutError: SSL shutdown timed out
This happens because asyncio sets a timeout on the close. If the client is idle, then when the timeout period is reached it raises the error above. This patch fixes that by adding TimeoutError to the list of exceptions caught when calling self.writer.wait_closed; it also tries to abort the transport to clean up resources. I tested with asyncio and with uvloop, where the transport classes are asyncio.sslproto._SSLProtocolTransport and uvloop.loop._SSLProtocolTransport respectively.
I am submitting this PR as an individual contributor under the existing Hypercorn MIT license.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a PR to fix #202. As the issue indicates, the error is:
File "[...]/hypercorn/asyncio/tcp_server.py", line 119, in _close await self.writer.wait_closed() File "/usr/lib/python3.12/asyncio/streams.py", line 364, in wait_closed await self._protocol._get_close_waiter(self) TimeoutError: SSL shutdown timed outThis happens because asyncio sets a timeout on the close. If the client is idle, then when the timeout period is reached it raises the error above. This patch fixes that by adding TimeoutError to the list of exceptions caught when calling self.writer.wait_closed; it also tries to abort the transport to clean up resources. I tested with asyncio and with uvloop, where the transport classes are asyncio.sslproto._SSLProtocolTransport and uvloop.loop._SSLProtocolTransport respectively.
I am submitting this PR as an individual contributor under the existing Hypercorn MIT license.