aio-libs / aio-libs/aiohttp

Websocket timeout needs a print

Open
#2,007 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
16.5k
Forks
2.4k
Avg merge
17h 22m
Merged PRs (30d)
212

Description

## Long story short

I use a websocket to detect when a page is closed. Every second the page will send a "beat" message. If after 5 seconds I didn't receive anything on the socket, then I consider it dead. The problem is that no timeout happens (or rather it happens only when there is a print in the reading loop).

## Expected behaviour

If no message is received for more than `receive_timeout` time, then a `TimeoutError` shall be raised.

(And the documentation should explain the `WebSocketResponse` constructor arguments, as well).

## Actual behaviour

This happens **only** if there is a `print` statement within the reading loop.

## Steps to reproduce

The original problem comes from the Bernard project. You can see [the reading loop](https://github.com/BernardFW/bernard/blob/d346ccb1511e4251304889a1aeeba21005ca3f5b/src/bernard/platforms/facebook/web.py#L328) as well as the [JS client](https://github.com/BernardFW/bernard/blob/d346ccb1511e4251304889a1aeeba21005ca3f5b/src/bernard/platforms/facebook/web.py#L184).

I could kind of isolate the problem, except that this time doing `print` does not help. You can find the code [in this gist](https://gist.github.com/Xowap/7e9ab562f87ea026b3a227e73fc991d3).

How to proceed:

1. Download the code from the gist and [ngrok](https://ngrok.com/)
2. Install a virtualenv with aiohttp
3. Run in the virtualenv the `test.py` file
4. Start ngrok by doing `ngrok http 8080`
5. Go to the HTTPS link
6. Keep the page open while you close the `ngrok` tunnel
7. Wait for 5 seconds
8. In the console you should see "GOT CLOSED" but instead nothing happens

## Your environment

- Python 3.6.1
- Elementary OS (Ubuntu Xenial)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.