socketio / socket.io-admin-ui

Admin UI for Socket.IO
https://admin.socket.io
MIT License
346 stars 94 forks source link

TypeError: Cannot set properties of undefined (setting 'transport') #55

Closed JK-Effects closed 1 year ago

JK-Effects commented 1 year ago

Issue: Local development in VS Code runs without problems or crashes. However, when I upload the application to a server, it runs until a Socket.io connection is established or the connected web page is refreshed. I don't know if this relates to the admin UI specifically as in the filepath below or if this is a Socket.io issue in general. Perhaps this also has to do with the middleware which holds up a request until an action has completed so that non-existent data cannot be accessed.

// middleware is executed on every request
var Map = require('file')

module.exports = (io, socket) => {
    socket.use(async (packet, next) => {
        var key = socket.handshake.auth.key
        var data = Map.get(key)

        while(!data.action) {    // true for finished or false for loading
            await new Promise(resolve => setTimeout(resolve,10))
        }
        socket.data = data
        next()
    })
}

Serverconsole:

/usr/src/app/node_modules/@socket.io/admin-ui/dist/index.js:233
socket.data._admin.transport = transport.name;
^

TypeError: Cannot set properties of undefined (setting 'transport')
at Socket.<anonymous> (/usr/src/app/node_modules/@socket.io/admin-ui/dist/index.js:233:42)
at Socket.emit (node:events:390:28)
at WebSocket.onPacket (/usr/src/app/node_modules/engine.io/build/socket.js:214:22)
at WebSocket.emit (node:events:390:28)
at WebSocket.onPacket (/usr/src/app/node_modules/engine.io/build/transport.js:92:14)
at WebSocket.onData (/usr/src/app/node_modules/engine.io/build/transport.js:101:14)
at WebSocket.<anonymous> (/usr/src/app/node_modules/engine.io/build/transports/websocket.js:20:19)
at WebSocket.emit (node:events:390:28)
at Receiver.receiverOnMessage (/usr/src/app/node_modules/ws/lib/websocket.js:1022:20)
at Receiver.emit (node:events:390:28)

Node.js v17.3.1
darrachequesne commented 1 year ago

Hi!

Yes, we keep track of some internal data in the socket.data._admin object: https://github.com/socketio/socket.io-admin-ui/blob/a8ce5262d51c9db44da048cb71186be322ee4929/lib/index.ts#L342-L347

So this line breaks:

socket.data = data

This might not be the best idea actually, but it is needed to work with multiple Socket.IO servers.

JK-Effects commented 1 year ago

Hi!

Yes, we keep track of some internal data in the socket.data._admin object:

https://github.com/socketio/socket.io-admin-ui/blob/a8ce5262d51c9db44da048cb71186be322ee4929/lib/index.ts#L342-L347

So this line breaks:

socket.data = data

This might not be the best idea actually, but it is needed to work with multiple Socket.IO servers.

Thanks for helping - after I changed socket.data to socket.socketData for example it worked fine