Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
da9e65e5
Unverified
Commit
da9e65e5
authored
Oct 23, 2026
by
vercel-fleet-prod[bot]
Committed by
GitHub
Oct 23, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make worker cleanup always async
Co-authored-by:
Tobias Koppers
<
1365881+sokra@users.noreply.github.com
>
parent
f9479a5a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
+7
-12
worker.ts
packages/next/src/lib/worker.ts
+7
-12
No files found.
packages/next/src/lib/worker.ts
View file @
da9e65e5
...
...
@@ -18,7 +18,7 @@ const RESTARTED = Symbol('restarted')
// profiles before falling back to jest-worker's regular (force-kill) shutdown.
const
CPU_PROFILE_FLUSH_TIMEOUT_MS
=
60
_000
const
cleanupWorkers
=
(
worker
:
JestWorker
):
Promise
<
void
>
|
undefined
=>
{
const
cleanupWorkers
=
async
(
worker
:
JestWorker
):
Promise
<
void
>
=>
{
const
children
:
ChildProcess
[]
=
[]
for
(
const
curWorker
of
((
worker
as
any
).
_workerPool
?.
_workers
||
[])
as
{
_child
?:
ChildProcess
...
...
@@ -30,14 +30,14 @@ const cleanupWorkers = (worker: JestWorker): Promise<void> | undefined => {
}
if
(
!
process
.
env
.
NEXT_CPU_PROF
)
{
return
undefined
return
}
// With CPU profiling enabled, workers save their profile when they receive
// SIGINT (see `server/lib/cpu-profile.ts`). jest-worker's `end()` force-kills
// workers that haven't exited after ~1s, which can cut off writing a large
// profile, so wait for the workers to exit first.
return
new
Promise
<
void
>
((
resolve
)
=>
{
await
new
Promise
<
void
>
((
resolve
)
=>
{
const
timer
=
setTimeout
(
resolve
,
CPU_PROFILE_FLUSH_TIMEOUT_MS
)
Promise
.
all
(
children
.
map
(
...
...
@@ -327,14 +327,14 @@ export class Worker {
this
.
_onActivityAbort
=
onActivityAbort
}
end
():
ReturnType
<
JestWorker
[
'end'
]
>
{
async
end
():
ReturnType
<
JestWorker
[
'end'
]
>
{
const
worker
=
this
.
_worker
if
(
!
worker
)
{
throw
new
Error
(
'Farm is ended, no more calls can be done to it'
)
}
const
flushed
=
cleanupWorkers
(
worker
)
this
.
_worker
=
undefined
return
flushed
?
flushed
.
then
(()
=>
worker
.
end
())
:
worker
.
end
()
await
cleanupWorkers
(
worker
)
return
worker
.
end
()
}
/**
...
...
@@ -343,13 +343,8 @@ export class Worker {
close
():
void
{
if
(
this
.
_worker
)
{
const
worker
=
this
.
_worker
const
flushed
=
cleanupWorkers
(
worker
)
this
.
_worker
=
undefined
if
(
flushed
)
{
flushed
.
then
(()
=>
worker
.
end
())
}
else
{
worker
.
end
()
}
cleanupWorkers
(
worker
).
then
(()
=>
worker
.
end
())
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment