Comments (5)
Awesome bug report :) That makes it an easy fix for me. Thanks a bunch!
On Feb 29, 2012 4:17 AM, "Chris Shoemaker" <
[email protected]>
wrote:
It has been very difficult to narrow this bug down, but it is 100%
reproducible. To reproduce:
- The server needs to be sending messages faster than the client can
receive them. I need to generate at least 100 messages from server to
client, but 200 is more reliable.- The length of the messages needs to be very consistent but gradually
increase. This is so you can observe a long sequence of identically
repeating frame headers. I accomplished this by embedding a counter
integer in the message, so when the counter was less than 9, the integer
serialized into one byte; when it was between 10 and 99, it required two
bytes, etc. For example, my first 9 messages were each 207 bytes long,
then messages 10-99 were each 208 bytes long, then messages 100+ were (or
would be) each 209 bytes long ( which would only be correct for a message
with counter > 99 ).- What you can observe, either through packet sniffing or by
instrumenting the client, is that the frame headers received by the client
show a frame length of 207 for 9 message, then 208 for messages 10-99, etc.
At least, that's what you should see. What actually happens is that,
under the right conditions, the receiver will consistently receive an frame
length that corresponds to a later message along with the message body for
the current body. In my example, somewhere between message 70-73 (that is,
still with a two digit counter in the message body) the sender will use the
message length of 209 bytes.- The problem is here:
https://github.com/einaros/ws/blob/06121f89f5ab52a242717f68e4d9dc36fe771f2a/lib/Sender.js#L126
The problem goes completely away if I force this line to always create a
new Buffer(totalLength).- If I inspect the contents of the outputBuffer just before the call to
Socket.send, (
https://github.com/einaros/ws/blob/06121f89f5ab52a242717f68e4d9dc36fe771f2a/lib/Sender.js#L172)
I see correct values, but when the bytes actually hit the wire (as
measured using wireshark) the incorrect value is sent.- The eventual symptom in my case was a "invalid utf8 sequence" error,
because the message length was one byte too high, so it would read the
first byte (129 = finalFragment | opcode) of the next frame and try to
validate it as utf8.- Of course, there's a one-liner fix that works, but avoids the use of
the _sendCache Buffer. How important is this cache? What are the
synchronization mechanisms for avoiding this bug?Note: I cannot reproduce this using a single machine. I have to use a
remote server.
Note2: The actual trigger points are sensitive to the message lengths.
With shorter messages, I can get it to fail around message 80-85, and with
longer messages, I can get it to fail around message 60-65.node version: 0.6.10
ws version: 0.4.7
arch: x86_64 linux
Reply to this email directly or view it on GitHub:
#35
from ws.
Could you try 0.4.8 and see if it still reproduces?
from ws.
I confirm. Bug fixed in 0.4.8.
from ws.
thanks einaros
from ws.
I had been pondering exactly why I added this lately. At some point (perhaps earlier in 0.6) I did see a perf gain from running it. With 0.6.11 and a newly written throughput benchmark, no perf difference could be found at all.
from ws.
Related Issues (20)
- Dual Triggering of WebSocket Events - ws.on('message') and stream.on('data') HOT 7
- Sec-WebSocket-Accept not found HOT 7
- ws issues with custom hostname HOT 2
- WebSocketServer.address() error needs more context HOT 2
- clientTracking - the client is not destroyed if the server closes or terminates the connection. HOT 2
- The code isn't working. HOT 14
- Is there anyway to disable the websocket closeTimeout? HOT 9
- Unhappy TypeScript when using compilerOptions: module: Node16 || NodeNext HOT 1
- Support sending Blob HOT 13
- WebSocket Ping-Pong Timeout and Connection Closure Failure HOT 3
- terminate() doesnt terminate instantly HOT 6
- ws doesn't work with sveltekit's adapter-cloudflare HOT 4
- Websocket opens randomly not everytime. HOT 5
- While building websocket-api:9.4.48.v20220622 with UAT, failed. (Test Case Failure) HOT 7
- query: difference between ws.onmessage = handler and ws.on('message', handler) HOT 2
- Messages are dispatched while microtask queue is not empty HOT 6
- Uhhh, what does .isAlive do again? HOT 2
- RangeError: Invalid WebSocket frame: MASK must be set HOT 1
- Invalid dns names should not cause an uncatchable fatal exception HOT 2
- Incorrect/incomplete documentation HOT 3
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 ws.