Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc92aff

Browse files
committed
fix: prevent possible race condition when killing tasks on failure
1 parentcb8a432 commitbc92aff

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

‎lib/resolveTaskFn.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,25 @@ const killExecaProcess = async (execaProcess) => {
7171
*
7272
*@param {Object} ctx
7373
*@param {execa.ExecaChildProcess<string>} execaChildProcess
74-
*@returns {() => void} Function that clears the interval that
74+
*@returns {() =>Promise<void>} Function that clears the interval that
7575
* checks the context.
7676
*/
7777
constinterruptExecutionOnError=(ctx,execaChildProcess)=>{
78-
letloopIntervalId
78+
letintervalId,killPromise
7979

8080
constloop=async()=>{
8181
if(ctx.errors.size>0){
82-
clearInterval(loopIntervalId)
83-
awaitkillExecaProcess(execaChildProcess)
82+
clearInterval(intervalId)
83+
killPromise=killExecaProcess(execaChildProcess)
84+
awaitkillPromise
8485
}
8586
}
8687

87-
loopIntervalId=setInterval(loop,ERROR_CHECK_INTERVAL)
88+
intervalId=setInterval(loop,ERROR_CHECK_INTERVAL)
8889

89-
return()=>{
90-
clearInterval(loopIntervalId)
90+
returnasync()=>{
91+
clearInterval(intervalId)
92+
awaitkillPromise
9193
}
9294
}
9395

@@ -155,7 +157,7 @@ export const resolveTaskFn = ({
155157

156158
constquitInterruptCheck=interruptExecutionOnError(ctx,execaChildProcess)
157159
constresult=awaitexecaChildProcess
158-
quitInterruptCheck()
160+
awaitquitInterruptCheck()
159161

160162
if(result.failed||result.killed||result.signal!=null){
161163
throwmakeErr(command,result,ctx)

‎test/resolveTaskFn.spec.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,31 @@ describe('resolveTaskFn', () => {
333333
`)
334334
})
335335

336+
it('should not kill long running tasks without errors in context',async()=>{
337+
execa.mockImplementationOnce(()=>
338+
createExecaReturnValue(
339+
{
340+
stdout:'a-ok',
341+
stderr:'',
342+
code:0,
343+
cmd:'mock cmd',
344+
failed:false,
345+
killed:false,
346+
signal:null,
347+
},
348+
1000
349+
)
350+
)
351+
352+
constcontext=getInitialState()
353+
consttaskFn=resolveTaskFn({command:'node'})
354+
consttaskPromise=taskFn(context)
355+
356+
jest.runOnlyPendingTimers()
357+
358+
awaitexpect(taskPromise).resolves.toEqual()
359+
})
360+
336361
it('should kill a long running task when an error is added to the context',async()=>{
337362
execa.mockImplementationOnce(()=>
338363
createExecaReturnValue(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp