question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

warnings/errors logged after disconnecting async http request

See original GitHub issue

Hi,

I’m using version 2.1.1. I set up a simple consumer (almost the same as the SSE example from the docs). If I use runserver, and connect a client and then disconnect, some ugly logging occurs some time after.

10 seconds after disconnecting, there’s a warning:

2018-05-19 21:20:20,065 - WARNING - server - Application instance <Task pending coro=<AsyncHttpConsumer.__call__() running at /home/justin/dev/django-eventstream/examples/chat/venv3/lib/python3.6/site-packages/channels/generic/http.py:25> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fb79ead45b8>()]>> for connection <WebRequest at 0x7fb79fb2ff28 method=GET uri=/events/ clientproto=HTTP/1.1> took too long to shut down and was killed.

A client disconnecting from a stream is something I would consider to be normal behavior, and should probably not cause noisy logging.

60 seconds after disconnecting, there’s an exception:

Exception in callback AsyncioSelectorReactor.callLater.<locals>.run() at /home/justin/dev/django-eventstream/examples/chat/venv3/lib/python3.6/site-packages/twisted/internet/asyncioreactor.py:287
handle: <TimerHandle when=275136.787314338 AsyncioSelectorReactor.callLater.<locals>.run() at /home/justin/dev/django-eventstream/examples/chat/venv3/lib/python3.6/site-packages/twisted/internet/asyncioreactor.py:287>
Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/home/justin/dev/django-eventstream/examples/chat/venv3/lib/python3.6/site-packages/twisted/internet/asyncioreactor.py", line 290, in run
    f(*args, **kwargs)
  File "/home/justin/dev/django-eventstream/examples/chat/venv3/lib/python3.6/site-packages/daphne/server.py", line 276, in timeout_checker
    protocol.check_timeouts()
  File "/home/justin/dev/django-eventstream/examples/chat/venv3/lib/python3.6/site-packages/daphne/http_protocol.py", line 260, in check_timeouts
    self.basic_error(503, b"Service Unavailable", "Application failed to respond within time limit.")
  File "/home/justin/dev/django-eventstream/examples/chat/venv3/lib/python3.6/site-packages/daphne/http_protocol.py", line 293, in basic_error
    (b"Content-Type", b"text/html; charset=utf-8"),
  File "/home/justin/dev/django-eventstream/examples/chat/venv3/lib/python3.6/site-packages/daphne/http_protocol.py", line 208, in handle_reply
    raise ValueError("HTTP response has already been started")
ValueError: HTTP response has already been started

That said, the warnings and errors appear to be harmless. New connections work as expected.

Here’s the consumer:

class EventsConsumer(AsyncHttpConsumer):
    async def handle(self, body):
        await self.send_headers(headers=[
	    ("Cache-Control", "no-cache"),
            ("Content-Type", "text/event-stream"),
        ])
        while True:
            payload = "data: %s\n\n" % datetime.now().isoformat()
            await self.send_body(payload.encode("utf-8"), more_body=True)
            await asyncio.sleep(1)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:26 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
vladi-petroffcommented, Apr 17, 2020

@andrewgodwin @erm Hello! It seems I have similar problem. I’m also using nice tutorial at hhttps://channels.readthedocs.io/en/latest/introduction.html about DjangoChannels. All understood, wrote my own one (suppose the same as there), everything is working, thanks for clear explanation on the site! However, I ran into a problem: when updating the chat page, the server throws this exception, moreover not in 60 seconds, but immediately (and after that I can’t send messages, so that’s quite harmful):

Exception in callback AsyncioSelectorReactor.callLater…run() at /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py:287 handle: .run() at /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py:287> Traceback (most recent call last): File “/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/events.py”, line 81, in _run self._context.run(self._callback, *self._args) File “/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py”, line 290, in run f(*args, **kwargs) File “/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/daphne/server.py”, line 229, in application_checker exception = application_instance.exception() asyncio.exceptions.CancelledError

(I am using WebsocketConsumer, python 3.8.2)

Actually, I suppose there is a problem with the disconnection with the server when updating the page. I tried to solve it myself but unfortunately didn’t succeed 😦 Could anybody please help me?

0reactions
jkarnegescommented, May 31, 2018

Thanks, all seems to be well now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

AsyncContext and I/O error handling (when peer disconnects)
The problem is that: ac.getResponse.getWriter().flush() does not throw IOException. So in order to get a error notification upon I/O operation you need to ......
Read more >
Configuring System Message Logging - Cisco
Messages appear on the console after the process that generated them has finished. Page 2. 30-2. Catalyst 3560 Switch Software Configuration Guide. OL- ......
Read more >
evFullMessageReceived Error in v2.9.0-beta-2211 - InetLab
Is it because of the client sending some wrong pdu or something ... shutdown send. client disconnected. in logs. and in bind response...
Read more >
Manual - A gentle introduction to Dancer2 - metacpan.org
The following will match any HTTP request to the path /myaction : ... Dancer2 can provide delayed (otherwise known as asynchronous) responses using...
Read more >
Pipeline run sequence - Azure - Microsoft Learn
Get ready for the job; Run each step in the job ... (Server jobs are an exception, since they run on the Azure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found