hapijs / nes

WebSocket adapter plugin for hapi routes
Other
502 stars 87 forks source link

Cannot read property 'socket' of undefined #232

Closed dominykas closed 6 years ago

dominykas commented 6 years ago

I haven't been able to reproduce this exactly just yet, but there's an error happening around https://github.com/hapijs/nes/blob/v8.0.0/lib/listener.js#L610 (await each(item.socket);).

In v6.5.1 _forEachSubscriber was fully sync. In v8.0.0 that is no longer the case. Because there is an await inside the loop, there is a gap where a client can get removed while another await itemize(item) is happening.

I'm also not 100% certain, but I think the previous behavior would have been to publish the message to all clients in sync, and not wait for that action to complete, whereas now it is all done in sequence?

As for possible fixes, I'm not 100% sure which is the best, but possibly an await Promise.all(Object.keys(this._items).map((key) => itemize(this._items[key])) to fire off the publish in parallel or check that item is still there inside itemize?

I'll try to prove my theory with a unit test if there's time left in the day...

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.