Merge pull request #309 from seemethere/fix_write_error_loop

Fixes write_error loop from bail_out function
This commit is contained in:
Raphael Deem 2017-01-17 18:11:22 -08:00 committed by GitHub
commit 5a6fb679c9

View File

@ -1,4 +1,5 @@
import asyncio import asyncio
import traceback
from functools import partial from functools import partial
from inspect import isawaitable from inspect import isawaitable
from signal import SIGINT, SIGTERM from signal import SIGINT, SIGTERM
@ -189,9 +190,15 @@ class HttpProtocol(asyncio.Protocol):
"Writing error failed, connection closed {}".format(e)) "Writing error failed, connection closed {}".format(e))
def bail_out(self, message): def bail_out(self, message):
exception = ServerError(message) if self.transport.is_closing():
self.write_error(exception) log.error(
log.error(message) "Connection closed before error was sent to user @ {}".format(
self.transport.get_extra_info('peername')))
log.debug('Error experienced:\n{}'.format(traceback.format_exc()))
else:
exception = ServerError(message)
self.write_error(exception)
log.error(message)
def cleanup(self): def cleanup(self):
self.parser = None self.parser = None