Repository navigation
readable event,outputs are different between v9.11 and v10.14.2 #25158
Description
Activity
Maybe /cc @nodejs/streams , if I'm not wrong, it seems that this is relevant to #17979.
#21690.const fs = require('fs'); const path = require('path'); // the content of `1.txt` is just `123456789` const rs = fs.createReadStream(path.join(__dirname, './1.txt'), { highWaterMark: 3, encoding: 'utf8' }) rs.on('readable', () => { let ch = rs.read(1) console.log('ch', ch); })
The outputs are different between
v9.11andv10.14.2:Node.js
v9.11:ch 1Nodej.js
v10.14.2:ch 1 ch 2@curry-wxj In English please. Let other guys can understand you. 用英语描述吧,让其他人能够看懂你的描述。
- changed the title
[-]绑定 readable事件,node版本不同,执行结果不同[/-][+] readable event,outputs are different between v9.11 and v10.14.2[/+]on Dec 24, 2018 - addedstreamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
on Dec 28, 2018 I'm sorry, but could someone please translate? I don't think this will get a lot of traction as-is.
@ryzokuken Hey, please look at my comment above, the example code above has different outputs between Node.js v9 and v10.
It seems that the readable event is emitted twice in v10.
@ZYSzys @curry-wxj the same behavior can be observed in master. I'm not quite up to speed with the streams subsystem, but seems like someone made a fix, it was backported to v10 but not v9 (since v9 has hit EOL).
Nobody should use v9 at this point anyway. If you feel like the current behavior (as observed on v10 and master) is a bug, feel free to make an issue for that.
@ZYSzys I guess this could be closed since the only reason the commit wasn't backported to v9 is because it is EOL?
I'd leave that up to you. Either way, the OP could reopen if they feel dissatisfied.
@ryzokuken The behavior on v8 LTS is the same as v9 which only emitted once(Oh, the commit isn’t backported to v8), but the v10(and master) is weird, IMHO.
I indeed thought it’s a bug on v10 and master, if I’m not wrong 🤔.Maybe @nodejs/streams could tell.
ping @nodejs/streams again.
Did the documentation change in #25375 fix this issue enough?Yes, I think so.
Reacted by ZYSzys
1.txt 内容为123456789,
代码:
const rs = fs.createReadStream(path.join(__dirname, './1.txt'), {
highWaterMark: 3,
encoding: 'utf8'
})
rs.on('readable', () => {
let ch = rs.read(1)
console.log('ch', ch);
})
9.11版本node 输出 ch 1(readable触发了1次)
10.14.2版本 输出 ch 1 ch 2 (readable触发了2次)
不太懂 readable 什么情况下会再次触发,