Skip to content
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(backups): backup worker inspect failed: address already in use #8197

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion @xen-orchestra/backups/runBackupWorker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ import { fork } from 'child_process'
const { warn } = createLogger('xo:backups:backupWorker')

const PATH = new URL('_backupWorker.mjs', import.meta.url).pathname
const DEFAULT_INSPECTOR_PORT = 9229

export function runBackupWorker(params, onLog) {
return new Promise((resolve, reject) => {
const worker = fork(PATH)
// run Node inspector on port+1 if --inspect or --inspect-brk
const inspectArg = process.execArgv.find(arg => arg.startsWith('--inspect') || arg.startsWith('--inspect-brk'))
const execArgv = inspectArg
? [
inspectArg.replace(/^(--inspect(-brk)?)(=([^:]+:)?(\d+))?$/, (_, prefix, brk, _fullMatch, host, port) => {
const basePort = port ? parseInt(port) : DEFAULT_INSPECTOR_PORT
return `${prefix}=${host || ''}${basePort + 1}`
}),
]
: []

const worker = fork(PATH, [], { execArgv })

worker.on('exit', (code, signal) => reject(new Error(`worker exited with code ${code} and signal ${signal}`)))
worker.on('error', reject)
Expand Down
Loading