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

Untreated error callbacks when using websockets #375

Merged
merged 1 commit into from
Nov 19, 2022

Conversation

bvanelli
Copy link
Contributor

@bvanelli bvanelli commented Oct 14, 2022

There are two things:

  • The parsing issue was caused by readline returning the actual error code (in this case 1001). I made it return b'' instead and EOF will be triggered in the next call
  • __bool__ was returning false every time it was disconnected. I'm returning now if self._client exists instead.

If you want to test, simply use the script

import asyncio
import nats


async def main():
    async def cb(msg):
        print(msg)
    ws = await nats.connect("ws://localhost", error_cb=cb)
    await ws.subscribe("hello", cb=cb)
    for i in range(100):
        await ws.publish("hello", f"hello world {i}".encode())
        await asyncio.sleep(5)


if __name__ == '__main__':
    asyncio.run(main())

And turn off the connection to NATS. This will cause now EOF in both implementations.

Closes #361

@bvanelli
Copy link
Contributor Author

@wallyqs do you have further points to address?

@wallyqs wallyqs merged commit 4f00525 into nats-io:main Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Untreated error callbacks when using websockets
2 participants