-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Memory spike when emitting large objects without enforcing WS-only transports #2872
Comments
Tagging @hunterloftis from Heroku Tech Team - wanted to follow this issue |
Thanks for the example, I could indeed reproduce the issue. It seems the ucs2decode method here consumes a lot of memory. It's called there: exports.encodePayload = function (packets, supportsBinary, callback) {
if (typeof supportsBinary === 'function') {
callback = supportsBinary;
supportsBinary = null;
}
// <= supportsBinary is true here, so the payload is encoded as binary
if (supportsBinary) {
return exports.encodePayloadAsBinary(packets, callback);
}
if (!packets.length) {
return callback('0:');
}
function encodeOne(packet, doneCallback) {
exports.encodePacket(packet, supportsBinary, false, function(message) {
doneCallback(null, setLengthHeader(message));
});
}
map(packets, encodeOne, function(err, results) {
return callback(results.join(''));
});
}; |
I can dive in when things clear up and see if I can get a fix (in about a week or so) and perhaps submit a PR. Unless you already have an idea on what's going on with |
It seems the behaviour was changed here: socketio/engine.io-parser@44c7aa5 |
Yet I'm not sure whether the statement |
This reverts commit 44c7aa5, which caused string payloads to be encoded as binary (so that huge string payloads were needlessly UTF-8-encoded). Related: socketio/socket.io#2872
This reverts commit 44c7aa5, which caused string payloads to be encoded as binary (so that huge string payloads were needlessly UTF-8-encoded). Related: socketio/socket.io#2872
Current behaviour
When there's no enforcement to use "Web Sockets" only as the transport
protocol, the server logs a memory spike (> 500%) when emitting a big sample
JSON.
When "Web Sockets" only are enforced, the server logs
nominal memory consumption values whilst emitting the sample JSON.
Steps to reproduce
I've created a repo illustrating this issue, https://github.com/TheProfs/socket-mem-leak
Expected behaviour
protocol, the server logs a nominal memory increase due to buffering, equal to the size of the emitted JSON (~10MB)
Setup
Heap Metrics
Listening on 3000, using default transport (websocket & xhr) Used heap size 34.91 MB new connection emitting 10 MB payload Used heap size 659.31 MB Used heap size 659.50 MB Used heap size 659.56 MB Used heap size 659.56 MB new connection emitting 10 MB payload Used heap size 593.52 MB Used heap size 593.65 MB Used heap size 593.68 MB Used heap size 593.68 MB
The text was updated successfully, but these errors were encountered: