Skip to content

Commit f1dc59f

Browse files
committed
fix: check if Unix Domain socket file exists before listening. (#921)
* docs: Update CHANGELOG. * fix: Check if Unix Domain socket file exists before listening. * Test
1 parent 5c37f12 commit f1dc59f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/phpDebug.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ class PhpDebugSession extends vscode.DebugSession {
414414
throw new Error('Cannot have port and socketPath set at the same time')
415415
}
416416
if (args.hostname?.toLowerCase()?.startsWith('unix://') === true) {
417+
if (fs.existsSync(args.hostname.substring(7))) {
418+
throw new Error(
419+
`File ${args.hostname.substring(7)} exists and cannot be used for Unix Domain socket`
420+
)
421+
}
417422
server.listen(args.hostname.substring(7))
418423
} else if (args.hostname?.startsWith('\\\\') === true) {
419424
server.listen(args.hostname)

src/test/adapter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ describe('PHP Debug Adapter', () => {
9292
client.waitForEvent('terminated'),
9393
])
9494
})
95+
;(process.platform === 'win32' ? it.skip : it)('should error on existing unix pipe', async () => {
96+
await assert.isRejected(
97+
client.launch({
98+
program,
99+
hostname: 'unix:///tmp',
100+
runtimeArgs: ['-dxdebug.client_host=unix:///tmp'],
101+
}),
102+
/File .+ exists and cannot be used for Unix Domain socket/
103+
)
104+
})
95105
})
96106

97107
describe('continuation commands', () => {

0 commit comments

Comments
 (0)