TypeError: Cannot set properties of undefined (setting 'transport')
JK-Effects opened this issue · comments
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
Hi!
Yes, we keep track of some internal data in the socket.data._admin
object:
socket.io-admin-ui/lib/index.ts
Lines 342 to 347 in a8ce526
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.
Hi!
Yes, we keep track of some internal data in the
socket.data._admin
object:socket.io-admin-ui/lib/index.ts
Lines 342 to 347 in a8ce526
So this line breaks:
socket.data = dataThis 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