-
Notifications
You must be signed in to change notification settings - Fork 4
dont drop user fd until node reads a synthetic EOF #93
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9dc5272
try keeping user fd alive longer
jackyzha0 9fe9f50
allow only just to test
jackyzha0 dc2c4a6
try timeout??
jackyzha0 8b9718d
repeat
jackyzha0 a9f5090
pause style buffering
jackyzha0 fde37ce
more print debugging
jackyzha0 6d42e4a
even more print
jackyzha0 66db866
cursed split appraoch
jackyzha0 07bac5a
try with stability period
jackyzha0 0e60642
oops fix option
jackyzha0 156c4db
oops fix the type defs
jackyzha0 989f76b
3.6.0
jackyzha0 8622502
remove try catch
jackyzha0 86e0add
try synthetic eof? (#95)
jackyzha0 0328fce
formatting and things
jackyzha0 1990998
rebump to 500x
jackyzha0 6ff1c28
wait for style
jackyzha0 dbfe16c
comments...
jackyzha0 8aca969
review comments
jackyzha0 1adb8bd
readd rust import, fix drop on wrapper side
jackyzha0 d3476d5
fix drop oops
jackyzha0 4427693
fix file parallelism
jackyzha0 c07e347
fix vitest
jackyzha0 92ca323
test with threads
jackyzha0 1fb83fb
forks instead maybe??
jackyzha0 2a34263
rebump repeads
jackyzha0 776afc9
oops remove only
jackyzha0 c65af58
write_syn_eof_to_fd helper instead of unsafe + forget
jackyzha0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@replit/ruspty-darwin-arm64", | ||
| "version": "3.5.3", | ||
| "version": "3.6.0", | ||
| "os": [ | ||
| "darwin" | ||
| ], | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@replit/ruspty-darwin-x64", | ||
| "version": "3.5.3", | ||
| "version": "3.6.0", | ||
| "os": [ | ||
| "darwin" | ||
| ], | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@replit/ruspty-linux-x64-gnu", | ||
| "version": "3.5.3", | ||
| "version": "3.6.0", | ||
| "os": [ | ||
| "linux" | ||
| ], | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,85 @@ | ||
| import { Transform } from 'node:stream'; | ||
| import { getSyntheticEofSequence } from './index.js'; | ||
|
|
||
| // keep in sync with lib.rs::SYNTHETIC_EOF | ||
| export const SYNTHETIC_EOF = getSyntheticEofSequence(); | ||
| export const EOF_EVENT = 'synthetic-eof'; | ||
|
|
||
| // get the longest suffix of buffer that is a prefix of SYNTHETIC_EOF | ||
| function getBufferEndPrefixLength(buffer: Buffer) { | ||
| const maxLen = Math.min(buffer.length, SYNTHETIC_EOF.length); | ||
| for (let len = maxLen; len > 0; len--) { | ||
| let match = true; | ||
| for (let i = 0; i < len; i++) { | ||
| if (buffer[buffer.length - len + i] !== SYNTHETIC_EOF[i]) { | ||
| match = false; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (match) { | ||
| return len; | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| export class SyntheticEOFDetector extends Transform { | ||
| buffer: Buffer; | ||
|
|
||
| constructor(options = {}) { | ||
| super(options); | ||
| this.buffer = Buffer.alloc(0); | ||
| } | ||
|
|
||
| _transform(chunk: Buffer, _encoding: string, callback: () => void) { | ||
| const searchData = Buffer.concat([this.buffer, chunk]); | ||
| const eofIndex = searchData.indexOf(SYNTHETIC_EOF); | ||
|
|
||
| if (eofIndex !== -1) { | ||
| // found EOF - emit everything before it | ||
| if (eofIndex > 0) { | ||
| this.push(searchData.subarray(0, eofIndex)); | ||
| } | ||
|
|
||
| this.emit(EOF_EVENT); | ||
|
|
||
| // emit everything after EOF (if any) and clear buffer | ||
| const afterEOF = searchData.subarray(eofIndex + SYNTHETIC_EOF.length); | ||
| if (afterEOF.length > 0) { | ||
| this.push(afterEOF); | ||
| } | ||
|
|
||
| this.buffer = Buffer.alloc(0); | ||
| } else { | ||
| // no EOF - buffer potential partial match at end | ||
|
|
||
| // get the longest suffix of buffer that is a prefix of SYNTHETIC_EOF | ||
| // and emit everything before it | ||
| // this is done for the case which the eof happened to be split across multiple chunks | ||
| const commonPrefixLen = getBufferEndPrefixLength(searchData); | ||
|
|
||
| if (commonPrefixLen > 0) { | ||
| const emitSize = searchData.length - commonPrefixLen; | ||
| if (emitSize > 0) { | ||
| this.push(searchData.subarray(0, emitSize)); | ||
| } | ||
| this.buffer = searchData.subarray(emitSize); | ||
| } else { | ||
| this.push(searchData); | ||
| this.buffer = Buffer.alloc(0); | ||
| } | ||
| } | ||
|
|
||
| callback(); | ||
| } | ||
|
|
||
| _flush(callback: () => void) { | ||
| if (this.buffer.length > 0) { | ||
| this.push(this.buffer); | ||
| } | ||
|
|
||
| callback(); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.