Comments (9)
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.
from websockets.
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.
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.
Thanks @metathink, great investatigation!
from websockets.
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.
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.
See #170 for the more general considerations.
from websockets.
@RemiCardona Once you merge your patch, it would be a good time to make a release, wouldn't it?
from websockets.
I released version 3.3 with this change.
from websockets.
Related Issues (20)
- No route to host----when access IPv6 address failed,no attempt was made to access an IPv4 address HOT 1
- How to close a client connection using the threading interface while stuck in ClientConnection.recv
- Can we get more attention in the threaded client interface? HOT 1
- Human-readable representation of a frame is too short HOT 2
- No module websockets.imports HOT 2
- Sync client stops process exit when running in a Thread if not explicitly closed HOT 5
- Python 3.11 incompatible with websockets\legacy\protocol.py Error "got an unexpected keyword argument 'loop'" HOT 1
- Strange problem, client cannot receive messages from the server, after sending a certain amount of messages. HOT 2
- Cannot Send message to a single client.
- handling multiple websocket client connections HOT 4
- Enable to connect ! invalid handshake HOT 7
- recv() is slow HOT 5
- Client state is incorrect HOT 1
- Feature batch receive HOT 2
- [QUESTION] Switching from websocket-client to websockets HOT 1
- Sync version of broadcast HOT 2
- Running Scheduled Task in Websokcets Or Scaling with multiple workers HOT 1
- await websocket.recv() block the coroutine loop. HOT 1
- When using websockets as a client, how to send a pong when receiving a ping? HOT 1
- Make MAX_LINE configurable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websockets.