mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-15 12:06:02 -04:00
fix(server): fix a potential deadlock when requesting a tarball worker (#7041)
This commit is contained in:
7
.changeset/chilled-ghosts-flow.md
Normal file
7
.changeset/chilled-ghosts-flow.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-server": patch
|
||||
"@pnpm/server": patch
|
||||
pnpm: patch
|
||||
---
|
||||
|
||||
Fix a bug causing the pnpm server to hang if a tarball worker was requested while another worker was exiting.
|
||||
@@ -64,7 +64,7 @@ export async function start (
|
||||
}
|
||||
throw new PnpmError('SERVER_MANIFEST_LOCKED', `Canceling startup of server (pid ${process.pid}) because another process got exclusive access to server.json`)
|
||||
}
|
||||
let server: null | { close: () => Promise<void> } = null
|
||||
let server: null | ReturnType<typeof createServer> = null
|
||||
onExit(() => {
|
||||
if (server !== null) {
|
||||
// Note that server.close returns a Promise, but we cannot wait for it because we may be
|
||||
@@ -118,6 +118,11 @@ export async function start (
|
||||
// Set fd to null so we only attempt to close it once.
|
||||
fd = null
|
||||
await close(fdForClose)
|
||||
|
||||
// Intentionally avoid returning control back to the caller until the server
|
||||
// exits. This defers cleanup operations that should not run before the server
|
||||
// finishes.
|
||||
await server.waitForClose
|
||||
}
|
||||
|
||||
async function getServerOptions (
|
||||
|
||||
@@ -166,7 +166,11 @@ export function createServer (
|
||||
listener = server.listen(opts.port, opts.hostname)
|
||||
}
|
||||
|
||||
return { close }
|
||||
const waitForClose = new Promise<void>((resolve) => listener.once('close', () => {
|
||||
resolve()
|
||||
}))
|
||||
|
||||
return { close, waitForClose }
|
||||
|
||||
async function close () {
|
||||
listener.close()
|
||||
|
||||
Reference in New Issue
Block a user