-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix notepack
's encoding problems
#570
Labels
bug
Something isn't working
Comments
Domiii
changed the title
Runtime runs out of memory due to performance bug in notepack's
When debugging big applications, Aug 26, 2021
encode
@dbux/runtime
runs out of memory due to performance bug in notepack's encode
Domiii
changed the title
When debugging big applications,
fix Sep 12, 2021
@dbux/runtime
runs out of memory due to performance bug in notepack's encode
notepack
's encoding problems
var msgpack = require('@msgpack/msgpack');
var Emitter = require('component-emitter');
exports.protocol = 5;
/**
* Packet types (see https://github.com/socketio/socket.io-protocol)
*/
var PacketType = (exports.PacketType = {
CONNECT: 0,
DISCONNECT: 1,
EVENT: 2,
ACK: 3,
CONNECT_ERROR: 4,
});
var isInteger =
Number.isInteger ||
function (value) {
return (
typeof value === "number" &&
isFinite(value) &&
Math.floor(value) === value
);
};
var isString = function (value) {
return typeof value === "string";
};
var isObject = function (value) {
return Object.prototype.toString.call(value) === "[object Object]";
};
function Encoder() { }
Encoder.prototype.encode = function (packet) {
console.warn(`msgpack ENCODE`, packet);
return [msgpack.encode(packet)];
};
function Decoder() { }
Emitter(Decoder.prototype);
Decoder.prototype.add = function (obj) {
console.warn(`msgpack DECODE`);
try {
var decoded = msgpack.decode(obj);
this.checkPacket(decoded);
this.emit("decoded", decoded);
}
catch (err) {
console.error(`DECODE error -`, err);
}
};
function exists(x) {
return x !== null && x !== undefined;
}
function isDataValid(decoded) {
switch (decoded.type) {
case PacketType.CONNECT:
return !exists(decoded.data) || isObject(decoded.data);
case PacketType.DISCONNECT:
return !exists(decoded.data);
case PacketType.CONNECT_ERROR:
return isString(decoded.data) || isObject(decoded.data);
default:
return Array.isArray(decoded.data);
}
}
Decoder.prototype.checkPacket = function (decoded) {
var isTypeValid =
isInteger(decoded.type) &&
decoded.type >= PacketType.CONNECT &&
decoded.type <= PacketType.CONNECT_ERROR;
if (!isTypeValid) {
throw new Error("invalid packet type");
}
if (!isString(decoded.nsp)) {
throw new Error("invalid namespace");
}
if (!isDataValid(decoded)) {
throw new Error("invalid payload");
}
var isAckValid = !exists(decoded.id) || isInteger(decoded.id);
if (!isAckValid) {
throw new Error("invalid packet id");
}
};
Decoder.prototype.destroy = function () { };
exports.Encoder = Encoder;
exports.Decoder = Decoder; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Big Notepack Problems
symbol
type not supported; workaround:code node_modules/notepack.io/lib/encode.js
, line 255case 'symbol': return _encode(bytes, defers, value.toString());
webpack
know that things changed:version
change to trigger a webpack rebuildcode node_modules/notepack.io/package.json
-> changeversion
Client
sends runtime data back to the server.Client
usessocket.io
withsocket.io-msgpack-parser
, which in turn usesnotepack.io
where encoding uses up way too much memorynotepack.io
:encode
is a crazy memory hog darrachequesne/notepack#27Solution #1
notepack.io
with@msgpack/msgpack
(usingwebpack.NormalModuleReplacementPlugin
)node
despite being tagged as universal)undefined
, while msgpack-javascript coercesundefined
tonull
undefined
becomesnull
after deserializing msgpack/msgpack-javascript#150symbol
)webpack
withpw=.*
)notepack
)Finalize it
dbux-common\src\msgpackParser.js
, but it should go into a new, more dedicated library (maybedbux-net
etc.)notepack.io
completelyNOTEs
socket.io
does not handle decode errors gracefully. It does not report the error. It does not notify the client of a connect error apparently.The text was updated successfully, but these errors were encountered: