Fix ArrayBuffer detached error with uWebSockets.js#5331
Fix ArrayBuffer detached error with uWebSockets.js#5331ruochenjia wants to merge 1 commit intosocketio:mainfrom
Conversation
|
Hi! I'm not sure that this should be done inside the library, but rather left to the user, depending on its use case (for performance purposes). What do you think? |
|
Executing async functions within a callback is a very common practice in JavaScript. Detaching a buffer after a period of time is not common and usually only happens in the web stream API or when the application runs out of memory. This unusual behavior makes it very hard to debug especially there is no related documentation in the library. Beginners might not even know that Most Performance is not an issue to consider at all because buffer received in a single message is usually small, which makes the copying process extremely fast especially when the |
The kind of change this PR does introduce
Current behavior
When using
engine.ioserver withuWebSockets.js, the message buffer becomes detached after executing some async tasks, and throwsTypeErrorwhen trying to access the buffer later on.New behavior
The original
ArrayBufferpassed by theuWebSockets.jsis always copied to prevent it being detached. This matches the behavior for a regularengine.ioserver using the built-inhttpmodule.The documentation of
uWebSockets.jsstates that for themessagehandler, the given ArrayBuffer is valid during the lifetime of this callback (until first await or return) and will be neutered.Other information (e.g. related issues)