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 traceback
from functools import partial
from inspect import isawaitable
from signal import SIGINT, SIGTERM
@ -189,6 +190,12 @@ class HttpProtocol(asyncio.Protocol):
"Writing error failed, connection closed {}".format(e))
def bail_out(self, message):
if self.transport.is_closing():
log.error(
"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)