Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not write on a closed transport #58

Merged
merged 2 commits into from
Jun 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions roll/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,18 @@ def write(self, *args):
payload += b'\r\n'
if self.response.body and not bodyless:
payload += self.response.body
self.transport.write(payload)
if not self.parser.should_keep_alive():
self.transport.close()
if self.transport.is_closing():
# Request has been aborted, thus socket as been closed, thus
# transport has been closed?
return
try:
self.transport.write(payload)
except RuntimeError: # transport may still be closed during write.
# TODO: Pass into error hook when write is async.
pass
else:
if not self.parser.should_keep_alive():
self.transport.close()


Route = namedtuple('Route', ['payload', 'vars'])
Expand Down