-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Decompression does not work on Node.js >= 12 if the BFINAL bit is set to 1 #1669
Comments
I don't think it's an issue in the library because given ws popularity this problem would have flooded the issue tracker. Add a listener for the ws.on('open', function() {
ws._socket.prependListener('data', console.log);
}); Also, in your example, you should register the various event listeners outside of the handler of the |
Yes, sure - it's strange, however, that it works when moving to node10. I followed your advice and added the listener to the internal socket. Data arrives - and it's the same for Node10 and Node12. Again, Node10 sees the data, Node12 doesn't. Now there are two things I don't understand here. Why's there a difference with compression (websocket-sharp is using .Net's DeflateStream) and why does it work with Node10. Edit: C# DeflateStream appears to yield the same result as https://nodejs.org/api/zlib.html#zlib_zlib_deflateraw_buffer_options_callback |
What are negotiated parameters? Are default values used? Are the messages fragmented? Try to bypass This is basically what const assert = require('assert');
const zlib = require('zlib');
const message = Buffer.from('a'.repeat(1024));
let flushed = false;
const deflateChunks = [];
const inflateChunks = [];
const deflate = zlib.createDeflateRaw();
const inflate = zlib.createInflateRaw();
deflate.on('data', function(chunk) {
deflateChunks.push(chunk);
});
inflate.on('data', function(chunk) {
inflateChunks.push(chunk);
});
deflate.write(message);
deflate.flush(zlib.constants.Z_SYNC_FLUSH, function() {
inflate.write(Buffer.concat(deflateChunks));
deflateChunks.length = 0;
inflate.flush(function() {
flushed = true;
const buf = Buffer.concat(inflateChunks);
inflateChunks.length = 0;
assert(buf.equals(message));
});
});
process.on('exit', function() {
assert(flushed);
}); |
Thank you for keeping up! I'll continue to follow the compression path... For the time being - this is what I can log from the C# server:
Assuming the server sends a string "Welcome" when the client connects. The client receives: It works with the python server, and receives: (1 byte difference - 0b fails, 0a works) Deflate of the "Welcome"-String however is actually <Buffer 0b 4f cd 49 ce cf 4d 05 00> (with 0b). Does this sound familar? |
const zlib = require('zlib');
const message = Buffer.from('Welcome');
const chunks = [];
const deflate = zlib.createDeflateRaw();
deflate.on('data', function(chunk) {
chunks.push(chunk);
});
deflate.write(message);
deflate.flush(zlib.constants.Z_SYNC_FLUSH, function() {
console.log(Buffer.concat(chunks).slice(0, -4))
}); Prints const zlib = require('zlib');
const chunks = [];
const inflate = zlib.createInflateRaw();
inflate.on('data', function(chunk) {
chunks.push(chunk);
});
inflate.write(
Buffer.from([0x0a, 0x4f, 0xcd, 0x49, 0xce, 0xcf, 0x4d, 0x05, 0x00])
);
inflate.write(Buffer.from([0x00, 0x00, 0xff, 0xff]));
inflate.flush(function() {
const buf = Buffer.concat(chunks);
chunks.length = 0;
console.log(buf.toString());
}); works as expected. If the first byte is changed to |
It's the latest version - 10.17.0. Now I tried the 11 versions - it seems to work for me until 11.10.1, and stops working with 11.11.0. Have to checkout the changelog. Now what's strange - this code
results in
|
It seems a regression introduced in nodejs/node@28db96f. If that commit is reverted my example above works even if the first byte of the buffer is const chunks = [];
const deflate = zlib.createDeflateRaw();
deflate.on('data', function(chunk) {
chunks.push(chunk);
});
deflate.on('end', function() {
console.log(Buffer.concat(chunks)); // <Buffer 0b 4f cd 49 ce cf 4d 05 00>
});
deflate.end(Buffer.from('Welcome')); This is what happens when using Do you want to open an issue in the Node.js repository? |
Yes, that's the only change related to zlib. Great that you were able to verify this. I would open an issue - I'm not sure though, why there's the '0x0b' instead of '0x0a'. Thanks for analysing! |
That's because the According to the spec https://tools.ietf.org/html/rfc7692#section-7.2.1
both are valid. I tested with Chrome and sent the same data |
Should be fixed by nodejs/node@0e89b64. |
Description
I want ws to connect to a self written WebSocket Server based on https://github.com/sta/websocket-sharp.
While the test program works when using NodeJS 10.17.0, it doesn't with v12 or v13 - although the client connects and can send data successfully to the server, it does not show any received data. Since it does not seem to respond on "ping", the server library closes the connection after some time.
The server cannot be too wrong, since another short test with https://github.com/theturtle32/WebSocket-Node succeeds.
Reproducible in:
Attachments:
The text was updated successfully, but these errors were encountered: