-
Notifications
You must be signed in to change notification settings - Fork 413
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(sandbox): catch exit errors #2800
Merged
+146
−81
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9a43a3f
fix(sandbox): catch exit errors
roggervalf 6e02943
test: fix test cases
roggervalf 0fb7154
test: try to fix a test case
roggervalf 3144a77
test: fix test case
roggervalf d69ce01
test: fix test case
roggervalf fd848d7
test: 2nd try
roggervalf ff91794
chore: add console for testing
roggervalf aef8839
chore: try new test change
roggervalf 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 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
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 |
---|---|---|
|
@@ -77,6 +77,44 @@ describe('Sandboxed process using child processes', () => { | |
|
||
await worker.close(); | ||
}); | ||
|
||
it('should allow to pass workerForkOptions with timeout', async function () { | ||
const processFile = __dirname + '/fixtures/fixture_processor.js'; | ||
|
||
const workerForkOptions = { | ||
timeout: 50, | ||
} as any; | ||
const worker = new Worker(queueName, processFile, { | ||
autorun: false, | ||
connection, | ||
prefix, | ||
drainDelay: 1, | ||
useWorkerThreads: false, | ||
workerForkOptions, | ||
}); | ||
|
||
const failing = new Promise<void>((resolve, reject) => { | ||
worker.on('failed', async (job, error) => { | ||
try { | ||
expect([ | ||
'Unexpected exit code: null signal: SIGTERM', | ||
'Unexpected exit code: 0 signal: null', | ||
]).to.include(error.message); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
|
||
await queue.add('test', { foo: 'bar' }); | ||
|
||
worker.run(); | ||
|
||
await failing; | ||
|
||
await worker.close(); | ||
}); | ||
}); | ||
}); | ||
|
||
|
@@ -1019,12 +1057,20 @@ function sandboxProcessTests( | |
useWorkerThreads, | ||
}); | ||
|
||
const job = await queue.add('test', { exitCode: 1 }); | ||
const failing = new Promise<void>((resolve, reject) => { | ||
worker.on('failed', async (job, error) => { | ||
try { | ||
expect(error.message).to.be.equal('Broken file processor'); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
|
||
await expect(job.waitUntilFinished(queueEvents)).to.be.rejectedWith( | ||
'Broken file processor', | ||
); | ||
await queue.add('test', { exitCode: 1 }); | ||
|
||
await failing; | ||
await worker.close(); | ||
}); | ||
|
||
|
@@ -1050,7 +1096,7 @@ function sandboxProcessTests( | |
}); | ||
}); | ||
|
||
it('should remove exited process', async () => { | ||
it('should release exited process', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as my comment above, this test case changes as it's not removing but releasing |
||
const processFile = __dirname + '/fixtures/fixture_processor_exit.js'; | ||
|
||
const worker = new Worker(queueName, processFile, { | ||
|
@@ -1072,7 +1118,7 @@ function sandboxProcessTests( | |
expect(Object.keys(worker['childPool'].retained)).to.have.lengthOf( | ||
0, | ||
); | ||
expect(worker['childPool'].getAllFree()).to.have.lengthOf(0); | ||
expect(worker['childPool'].getAllFree()).to.have.lengthOf(1); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
|
@@ -1097,7 +1143,10 @@ function sandboxProcessTests( | |
}); | ||
|
||
// acquire and release a child here so we know it has it's full termination handler setup | ||
const initializedChild = await worker['childPool'].retain(processFile); | ||
const initializedChild = await worker['childPool'].retain( | ||
processFile, | ||
() => {}, | ||
); | ||
await worker['childPool'].release(initializedChild); | ||
|
||
// await this After we've added the job | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the past, we are removing this child in this handler but in sandbox file, depending on exit error we are removing or releasing. Removing this logic and handling it in sandbox