Skip to content

Error serialising sockets with session stores #7

Closed

Description

@liemnotliam

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

handshake: socket.handshake,
contains redis related things in 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?

Activity

  1. darrachequesne commented on May 15, 2021

    @darrachequesne
    Member

    maybe socket.io-admin could filter the handshake object based on its interface

    Sounds good to me. Would you have time to open a PR for this?

  2. liemnotliam commented on May 21, 2021

    @liemnotliam
    Author

    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
    image

  3. darrachequesne commented on May 22, 2021

    @darrachequesne
    Member

    I think the easiest way would indeed be to hardcode them, which is fine in this case I think.

  4. darrachequesne commented on Jun 2, 2021

    @darrachequesne
    Member

    This should be fixed by 1cf991e, included in version 0.1.2.

  5. added this to the 0.1.2 milestone on Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions