stream: the position of _read() is wrong#38292
stream: the position of _read() is wrong#38292helloyou2012 wants to merge 1 commit intonodejs:masterfrom
Conversation
|
Hi @helloyou2012, could you remove the merge commit from your branch? Merge commits tend to break the tooling, you can use node/doc/guides/contributing/pull-requests.md Lines 215 to 217 in 54322b8 |
|
@nodejs/streams |
mcollina
left a comment
There was a problem hiding this comment.
Why is wrong? Can you please expand?
Can you please add a unit test?
ronag
left a comment
There was a problem hiding this comment.
Needs test and also a little unsure what exactly we are solving here. If I would guess:
- Currently
this.poscould actually be larger than the file size, which is a little weird. - Currently
this.posis what we have requested, but necessarily what we have read.
|
@mcollina see this issue: #33940, this node/lib/internal/streams/readable.js Line 487 in d4f33f1 _read(n) multiple times with n= highWaterMark, but the bytesRead may be not equal to n, then the data will loss. Example:
|
|
The problem arised because current implementation assumed next position to start reading is node/lib/internal/fs/streams.js Lines 275 to 277 in d4f33f1 But in reality, it does not necessarily read node/lib/internal/fs/streams.js Line 246 in d4f33f1 As a result, some bytes in file may be skipped. The "assumed" reading is longer than the "actual". About the test, the issue occurred because |
ronag
left a comment
There was a problem hiding this comment.
I think this change could make sense. But we need a test.
Good question. I'm not sure I don't think I ever wrote such a test in Node - A good way to try is to take the test case from #33940 and to try to make a smaller isolated case from it (shorter interval and smaller watermark) @nodejs/fs |
|
I added test case. @ronag @benjamingr |
| highWaterMark: hwm, | ||
| start: cur | ||
| }); | ||
| stream.on('data', common.mustCallAtLeast((chunk) => { |
There was a problem hiding this comment.
Any reason this is a mustCAllAtLeast and not a mustCall?
There was a problem hiding this comment.
mustCall is exact times, but this place will call at least 1 time not exact 1 time.
benjamingr
left a comment
There was a problem hiding this comment.
LGTM if the test passes after this and fails in master
|
Also thank you for the meaningful contribution and working with us 🙏 |
mcollina
left a comment
There was a problem hiding this comment.
lgtm, hopefully the setInterval test would not fail in CI.
ronag
left a comment
There was a problem hiding this comment.
LGTM. Was wondering why this hasn't landed yet. Turns out it's my fault.
|
I think there is a problem on arm with the new test. @helloyou2012 |
Yes, the test timed out. I think it is better to set a time after which to exit safely. I will fix later. |
|
Removing the author ready label as there's still work to be done here. |
|
@helloyou2012 this still seems to have problems passing. Could you try and look at the CI failures? I started another CI just in case. |
|
It failed cause of |
|
This CI all passed. |
|
Landed in d826f6b |
Fixes: #33940