This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
net: Avoid tickDepth warnings on small writes #4676
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stumbled upon this running a benchmark that was (incorrectly) doing a very small write in the callback of a very small write.
Since the write was small, it was entirely flushed, and the callback was called on nextTick by the Stream.Writable class (so as to prevent a "sometimes-sync" API).
However, the net.Socket class calls its
_write
callback synchronously when the chunk was entirely flushed, leading to a tickDepth warning.Synchronous write streams can still trigger the tickDepth warning, but at least we should not cause this in net.Socket, and the alternative is a stack overflow. (Another alternative way to solve this would be for net.Socket to always defer its write cb, but that is giving up a significant optimization.)
Also, this exposes process.tickDepth as a read-only property, which is pretty useful.