GithubHelp home page GithubHelp logo

Comments (9)

 avatar commented on June 25, 2024 1

For information, I came across this problem using websockets==3.2 while I was trying to use many "await websocket.send(data)" in parallel. WebSocketCommonProtocol.send() calls asyncio.StreamWriter.drain() which apparently must not be called twice in parallel.

I was able to reproduce it without websockets and opened an issue here: http://bugs.python.org/issue29930
I think it might be interesting to follow the evolution of this issue and make changes in websockets if necessary.

@aaugustin

from websockets.

aaugustin avatar aaugustin commented on June 25, 2024

I have no idea. Unfortunately, my crystal ball is momentarily out of order, so I can't read the code you have carefully omitted from this bug report.

from websockets.

aaugustin avatar aaugustin commented on June 25, 2024

Regardless of how you're running into this problem, make sure you're using the latest version of asyncio or try your code with Python 3.4, as some bugs have been fixed recently in this area.

from websockets.

aaugustin avatar aaugustin commented on June 25, 2024

Thanks @metathink, great investatigation!

from websockets.

RemiCardona avatar RemiCardona commented on June 25, 2024

I'm glad to see this being reopened. I've been investigating this on and off for the past 2 weeks and came to the same conclusion: drain is nowhere near "thread"/task safe. And because websockets may call write_frame independently (IOW: in another Task) of user code through the PONG reply, there's a chance things may break.

I've been a able to reliably force the bug using https://github.com/mariusae/trickle (with a few local fixes to make it work with CLOEXEC sockets that python uses) to slow down network write speeds, which forces the sender to fill up the write buffer, thus revealing the bug.

The patch above simply adds a lock around drain() and I haven't been able to get this code to fail.

I've also been reading njs's "post async/await" post and the more I think about it, a module like websocket (and many others, really) could probably do away with all the whole transports._FlowControlMixin: writes could/should be coroutines that "block" until frame data has been flushed to kernel/libc buffers. The userspace/asyncio buffering is counterproductive. The drain fail being just the tip of the iceberg. But that's work for another PR.

from websockets.

aaugustin avatar aaugustin commented on June 25, 2024

Thanks for the patch, let's do that. Even if the issue eventually gets fixed in Python, we need to work around it in versions of Python where it exists.

from websockets.

aaugustin avatar aaugustin commented on June 25, 2024

See #170 for the more general considerations.

from websockets.

aaugustin avatar aaugustin commented on June 25, 2024

@RemiCardona Once you merge your patch, it would be a good time to make a release, wouldn't it?

from websockets.

aaugustin avatar aaugustin commented on June 25, 2024

I released version 3.3 with this change.

from websockets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.