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

EofStream and autoclose #2784

Closed
thomaszdxsn opened this issue Mar 2, 2018 · 8 comments
Closed

EofStream and autoclose #2784

thomaszdxsn opened this issue Mar 2, 2018 · 8 comments

Comments

@thomaszdxsn
Copy link
Contributor

thomaszdxsn commented Mar 2, 2018

Long story short

Hi, I meet a problem with websocket's client message, sometimes I will receive EofStream object instead of bytes or str(so broken my program).I don't now what's this object.But I guess it means EOF right?

async for msg in self._ws_conn:
    msg_data = json.loads(msg_data)  # msg_data maybe EofStream

Expected behaviour

If EofStream meaning EOF, Why not just close this websocket connection, beacuase I see ws_connect() have a argument named 'autoclose', it default to True?

Or EofStream has other meaning?

@asvetlov
Copy link
Member

asvetlov commented Mar 6, 2018

Is it aiohttp 3.0?

@thomaszdxsn
Copy link
Contributor Author

"version": "==3.0.6"

It's my pipfile.lock's content

@asvetlov
Copy link
Member

asvetlov commented Mar 6, 2018

This is a bug, iteration over websocket messages should be stopped without returning stop marker to user.
Would you work on bugfix?

@thomaszdxsn
Copy link
Contributor Author

yeah, i should take time to read contribute guide

@asvetlov
Copy link
Member

Fixed by #2814, released by aiohttp 3.1

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
@socketpair socketpair reopened this Jun 22, 2022
@socketpair
Copy link
Contributor

socketpair commented Jun 22, 2022

aiohttp 3.8.1

await websocket.receive_json() Will die with TypeError on WSMsgType.CLOSED.

 async def __anext__(self) -> WSMessage:
        msg = await self.receive()
        if msg.type in (WSMsgType.CLOSE, WSMsgType.CLOSING, WSMsgType.CLOSED):
            raise StopAsyncIteration
        return msg

Yes, bug is fixed in iterator but NOT fixed for websocket.receive_* functions, like receive_json()

I would raise RuntimeError or so if corresponding message "type" (like bytes, str, or json) can not be received.

@socketpair
Copy link
Contributor

see #6800

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants