Repository navigation
Closed
Milestone
Description
I have an application that shares an express session with socket.io. The session is backed by a redis store. The admin runs fine when the socket.io server starts but crashes when a client connects to the socket.io server.
../app/node_modules/notepack.io/lib/encode.js:256
throw new Error('Could not encode');
^
Error: Could not encode
at _encode (../app/node_modules/notepack.io/lib/encode.js:256:13)
at _encode (../app/node_modules/notepack.io/lib/encode.js:162:19)
at _encode (../app/node_modules/notepack.io/lib/encode.js:246:17)
at _encode (../app/node_modules/notepack.io/lib/encode.js:246:17)
at _encode (../app/node_modules/notepack.io/lib/encode.js:246:17)
at _encode (../app/node_modules/notepack.io/lib/encode.js:246:17)
at _encode (../app/node_modules/notepack.io/lib/encode.js:246:17)
at _encode (../app/node_modules/notepack.io/lib/encode.js:162:19)
at _encode (../app/node_modules/notepack.io/lib/encode.js:246:17)
at _encode (../app/node_modules/notepack.io/lib/encode.js:162:19)
at Object.encode (../app/node_modules/notepack.io/lib/encode.js:261:41)
at RedisAdapter.broadcast (../app/node_modules/socket.io-redis/dist/index.js:313:33)
at BroadcastOperator.emit (../app/node_modules/socket.io/dist/broadcast-operator.js:113:22)
at Namespace.emit (../app/node_modules/socket.io/dist/namespace.js:168:73)
at Namespace.<anonymous> (../app/node_modules/@socket.io/admin-ui/dist/index.js:231:24)
at Namespace.emit (events.js:315:20)
From what I gathered, the crash happens because the socket serialisation in
socket.io-admin-ui/lib/index.ts
Line 349 in f453422
| handshake: socket.handshake, |
socket.handshake:
{
...
sessionStore: RedisStore {
_events: [Object: null prototype] {
disconnect: [Function: ondisconnect],
connect: [Function: onconnect]
},
_eventsCount: 2,
_maxListeners: undefined,
prefix: 'sess:',
scanCount: 100,
serializer: Object [JSON] {},
client: RedisClient {
...
}
I'm not quite sure where that sessionStore is added to socket.handshake but maybe socket.io-admin could filter the handshake object based on its interface in https://github.com/socketio/socket.io/blob/b84ed1e41c9053792caf58974c5de9395bfd509f/lib/socket.ts#L64?
Metadata
Metadata
Assignees
Labels
No labels
Activity
darrachequesne commentedon May 15, 2021
Sounds good to me. Would you have time to open a PR for this?
liemnotliam commentedon May 21, 2021
Haven't done a lot of TypeScript but there doesn't seem to be a nice way to get the interface keys without hardcoding them, any thoughts or suggestions?
TS playground link

darrachequesne commentedon May 22, 2021
I think the easiest way would indeed be to hardcode them, which is fine in this case I think.
fix(server): only serialize required handshake attributes
darrachequesne commentedon Jun 2, 2021
This should be fixed by 1cf991e, included in version
0.1.2.