-
Notifications
You must be signed in to change notification settings - Fork 102
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
Received WebSocket frames are malformed if fragmented #48
Comments
i uploaded a screencast with the wireshark frames inspected for those who can't/don't want to install/use wireshark: |
Thanks for the TCP dump. I've extracted the data portion of the transcript and reproduced it below. This contains the frame number, which peer sent the packet, the packet length, and its data:
Stepping through it: Frame 1: the client sends Frame 2: the server sends Frame 3: the client sends Frame 4: the server sends Frame 5: the client sends Frame 6: the client sends This transcript looks fine to me and I'm not sure why the server is returning an error after the client's first message. So, I got out the example server from this repo. Add this line to the socket.on('data', function(data) { console.log('parse', data) }); With the example server running, I made this script. It opens a TCP connection to the server, and performs a WebSocket handshake. Then it sends the data from frames 1 and 3 at a controllable delay. var net = require('net'),
websocket = require('websocket-driver');
var INTERVAL = parseInt(process.argv[2], 10);
var CHUNKS = [
'81',
'af f0 e2 92 e9 8b c0 e4 8c 82 91 fb 86 9e c0 a8',
'cb c1 c0 be cb 83 97 e2 99 9f 90 e6 cb ca b9 b0',
'd8 d2 bf be cb 9d 91 f5 cb ca c0 f1 86 9e 8c f7',
'8a 84 c0 ef'
];
var socket = net.connect(7000, 'localhost'),
driver = websocket.client('ws://localhost:7000/');
socket.on('error', function() {});
socket.pipe(driver.io).pipe(socket);
driver.on('open', function() {
console.log('open');
var i = 0;
setInterval(function() {
var chunk = CHUNKS[i++];
if (chunk === undefined) return;
var buf = new Buffer(chunk.replace(/ /g, ''), 'hex');
socket.write(buf);
}, INTERVAL);
});
driver.on('close', function(close) {
console.log('close', close.code, close.reason);
});
driver.messages.on('data', function(message) {
console.log('message', message);
});
driver.start(); If you run this script with interval
The server processes this data as a text frame as described about and echoes it to the client, which prints
If you leave the server running, you'll see data like this on the server:
The final chunk of our test input also begins If we increase the interval to
Lines 1 to 4 are as before. On line 5, the client sends a pong frame I mention all this to demonstrate that if frames are somehow interleaved into the parser, then they won't make sense and the parser will spit them out. However the transcript you gave looks valid to me -- parsing it 'by hand' it looks fine, the frame contents are of the correct sizes and arrive in packets all together. And when we replay it without interleaving other things, it works fine. So I wonder if there's some way the server you're talking to could be interleaving inputs, or delaying or chopping the input up in some way. Is any of that helpful and does it sound like what might be happening in your system? |
wow thanks @jcoglan for taking so much time to look into this. With "the server you're talking to" I'm not sure what you mean. I though it'd be faye-websocket-node... |
What I mean is that the only way I can find to trigger this error is to deliberately insert data into the middle of frames. The The server is most likely using a construction like in the docs to set up the WebSocket on the server side. Code like this has access to the |
@jreinert What version of Meteor are you using? Do you observe this in production or in development? If in production, does your app run behind a proxy? |
i'm using the latest version (1.2) and it's happening in development. |
I didn't have a chance to look into it and I'm not sure if I will soon, especially if there's isn't an easy reproduction. |
haven't gotten anywhere no.. |
I've been writing issues starting from NodeJS over to Meteor over to SockJS over to this project now all concerning the same issue and being directed to another project. Hopefully I'm at the end of the rainbow now writing this here. The issue is as follows:
I'm sending websockets over to a meteor app (which uses SockJS which uses faye-websocket apparently). One of the frames is fragmented over two TCP packets. This results in the websocket being closed due to an unknown opcode (13). Here's the wireshark dump of the communication:
http://p.jreinert.com/yM9/
The text was updated successfully, but these errors were encountered: