hapi-plugin-websocket icon indicating copy to clipboard operation
hapi-plugin-websocket copied to clipboard

Fix: Initial messages could be lost

Open joshkel opened this issue 2 years ago • 2 comments

The use of await when handling the "initially" WebSocket message may cause incoming messages to be lost. Event handlers like ws.on('message', ...) may not get installed until after the asynchronous method completes, so any WebSocket events during that time period aren't handled.

Fixes #20

joshkel avatar Sep 12 '22 20:09 joshkel

Yes, correct: the "await" for the initial injected HTTP message might need more time than the arrival of the first Websocket message. But the solution is not such easy as to just use a promise callback instead, because the authorization has to be checked by the initial simulated HTTP request before a Websocket message should be processed. I've to look what the more correct solution is to resolve your issue and NOT cause a security issue.

rse avatar Apr 27 '23 17:04 rse

@rse Thank you for pointing that out. I just pushed a potential fix.

joshkel avatar May 07 '23 20:05 joshkel