Closed cenullum closed 3 months ago
websocket.terminate()
destroys the underlying socket. If the there is buffered data, that data is read and then the 'close'
event is emitted. Buffered data is not discarded by design.
Is there a way to delete buffered data manually or can limit buffered data count or longer polling interval?
Is there a way to delete buffered data manually or can limit buffered data count or longer polling interval?
No, the amount of buffered data is defined by https://nodejs.org/api/stream.html#readablereadablehighwatermark but you can't discard it.
@lpinca Is there a way to artificially delay adding data to the buffer? If there is any other recommendation I'm listening
No, that's how Node.js streams work. If you don't care about the the messages received after calling websocket.terminate()
, you can remove the listener for the 'message'
event.
I'm closing this as answered.
Is there an existing issue for this?
Description
I'm wanted to add rate limiter with https://www.npmjs.com/package/rate-limiter-flexible then terminate function seems doesnt terminate ws instantly then made my own rate limiter however same result. After limit request of client reached server still can receives request from client.
ws version
7.5.9
Node.js Version
v16.16.0
System
Expected result
I expected to not receive another requests after 50 limit in the video. So I wanted dos2 result but got dos
Actual result
After terminate() I'm getting 300 more requests from client. I recorded a video and made a sample project
Attachments