tlaverdure / laravel-echo-server

Socket.io server for Laravel Echo
MIT License
2.65k stars 510 forks source link

Fixes Cannot read property 'socketId' of undefined #535

Open dkulyk opened 4 years ago

dkulyk commented 4 years ago

This PR adds check for member and reduce loops find + filter => only filter

On highload projects sometimes I catch:

(node:5114) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'socketId' of undefined
    at /usr/lib64/node_modules/laravel-echo-server/dist/channels/presence-channel.js:74:81
    at Array.filter (<anonymous>)
    at /usr/lib64/node_modules/laravel-echo-server/dist/channels/presence-channel.js:74:31
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

a member is not present on a channel.

devzom commented 2 years ago

Bump , any solution?

cmcfadden commented 2 years ago

bump, would love to see this merged, we encountered this today.

ulc-brian commented 2 years ago

We are also having this problem now, the error looks very close to the above and thinking this might fix it. It is basically causing the Laravel Echo server to crash about once a minute where supervisor then restarts it. Here is the stack trace we are getting:

/usr/local/lib/node_modules/laravel-echo-server/dist/channels/presence-channel.js:75
            members = members.filter(function (m) { return m.socketId != member.socketId; });
                                                                                ^

TypeError: Cannot read properties of undefined (reading 'socketId')
    at /usr/local/lib/node_modules/laravel-echo-server/dist/channels/presence-channel.js:75:81
    at Array.filter (<anonymous>)
    at /usr/local/lib/node_modules/laravel-echo-server/dist/channels/presence-channel.js:75:31
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

We are currently using Laravel Echo Server 1.6.2

cmcfadden commented 2 years ago

@ulc-brian if it's helpful, we have a fixed branch we're using at http://github.com/umn-latis/laravel-echo-server, in npm as @umn-latis/laravel-echo-server. We're doing thousands of concurrent connects on it without crashes (knock on wood).

ulc-brian commented 2 years ago

Awesome, thanks for that @cmcfadden, I will likely have to do that until this is merged.