Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add more strict check for streams in `util.isStream()' #628

Merged
merged 3 commits into from
Mar 27, 2021

Conversation

jarrodconnolly
Copy link
Contributor

Fixes #625 - Added a similar check that the Node.js project uses.

The check used in undici was the reverse of the problem in the Node.js project. The commit mentioned in #625 shows they were missing the check for .on() where undici was missing the checks for pipe() or `write()'.

In its current state the util.isStream() allows Stream, correctly returns false on Buffer, but does allow EventEmitter since it also has .on().

I changed the util.isStream() method to match what the Node.js project uses.

In https://github.com/nodejs/undici/blob/main/lib/core/request.js#L39 I switched to using the newly exposed util.isReadable() since the error message there indicates that it should be a Readable stream. There are likely other places that should use the more specific util.isReadable().

I had to change the test stream body without destroy in test/stream-compat.js that was passing an EventEmitter as the request body since that case now fails differently than the test was looking for. I believe I kept the spirit of the test intact.

Hopefully, this is the direction intended for the issue.

@codecov-io
Copy link

codecov-io commented Mar 27, 2021

Codecov Report

Merging #628 (81dea3a) into main (0de02d3) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #628      +/-   ##
==========================================
- Coverage   98.02%   97.96%   -0.07%     
==========================================
  Files          17       17              
  Lines        1572     1574       +2     
==========================================
+ Hits         1541     1542       +1     
- Misses         31       32       +1     
Impacted Files Coverage Δ
lib/core/request.js 96.93% <100.00%> (ø)
lib/core/util.js 86.84% <100.00%> (-2.35%) ⬇️
lib/llhttp/parser.js 93.05% <0.00%> (+0.69%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0de02d3...81dea3a. Read the comment docs.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ronag ronag merged commit f098adf into nodejs:main Mar 27, 2021
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* fix: add more strict check for streams in `util.isStream()'

* fix: split `isReadable()` & `isWritable()` for more specific checks

* fix: delete was not working to remove `destroy()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't mistake buffers as streams
4 participants