-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: the position of _read() is wrong
Fixes: #33940 PR-URL: #38292 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
- Loading branch information
1 parent
bfe02b8
commit a18b1ff
Showing
2 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use strict'; | ||
|
||
// Refs: https://github.com/nodejs/node/issues/33940 | ||
|
||
const common = require('../common'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
|
||
tmpdir.refresh(); | ||
|
||
const file = path.join(tmpdir.path, '/read_stream_pos_test.txt'); | ||
|
||
fs.writeFileSync(file, ''); | ||
|
||
let counter = 0; | ||
|
||
setInterval(() => { | ||
counter = counter + 1; | ||
const line = `hello at ${counter}\n`; | ||
fs.writeFileSync(file, line, { flag: 'a' }); | ||
}, 1); | ||
|
||
const hwm = 10; | ||
let bufs = []; | ||
let isLow = false; | ||
let cur = 0; | ||
let stream; | ||
|
||
setInterval(() => { | ||
if (stream) return; | ||
|
||
stream = fs.createReadStream(file, { | ||
highWaterMark: hwm, | ||
start: cur | ||
}); | ||
stream.on('data', common.mustCallAtLeast((chunk) => { | ||
cur += chunk.length; | ||
bufs.push(chunk); | ||
if (isLow) { | ||
const brokenLines = Buffer.concat(bufs).toString() | ||
.split('\n') | ||
.filter((line) => { | ||
const s = 'hello at'.slice(0, line.length); | ||
if (line && !line.startsWith(s)) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
assert.strictEqual(brokenLines.length, 0); | ||
process.exit(); | ||
return; | ||
} | ||
if (chunk.length !== hwm) { | ||
isLow = true; | ||
} | ||
})); | ||
stream.on('end', () => { | ||
stream = null; | ||
isLow = false; | ||
bufs = []; | ||
}); | ||
}, 10); | ||
|
||
// Time longer than 90 seconds to exit safely | ||
setTimeout(() => { | ||
process.exit(); | ||
}, 90000); |