Angel98518
9cf88df67b
Improve streamToBuffer error handling and memory safety ( #17255 )
...
## Description
This PR improves error handling and memory safety for the streamToBuffer
utility function.
### Changes
- Add proper cleanup of event listeners to prevent memory leaks
- Add checks for already-ended streams to handle edge cases gracefully
- Add protection against multiple resolve/reject calls with isResolved
flag
- Add handling for close events with appropriate error messages
- Improve robustness when streams are destroyed or closed externally
### Impact
This fixes potential memory leaks and race conditions when streams are
cancelled, destroyed, or closed before completion.
### Code Statistics
- 1 file changed
- ~53 lines added, 9 lines modified
- ~95% code changes (functional improvements)
---------
Co-authored-by: GitTensor Miner <miner@gittensor.io >
Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com >
2026-01-20 16:19:47 +00:00