diff --git a/src/phpDebug.ts b/src/phpDebug.ts index a04eed72..b6b817d8 100644 --- a/src/phpDebug.ts +++ b/src/phpDebug.ts @@ -414,6 +414,11 @@ class PhpDebugSession extends vscode.DebugSession { throw new Error('Cannot have port and socketPath set at the same time') } if (args.hostname?.toLowerCase()?.startsWith('unix://') === true) { + if (fs.existsSync(args.hostname.substring(7))) { + throw new Error( + `File ${args.hostname.substring(7)} exists and cannot be used for Unix Domain socket` + ) + } server.listen(args.hostname.substring(7)) } else if (args.hostname?.startsWith('\\\\') === true) { server.listen(args.hostname) diff --git a/src/test/adapter.ts b/src/test/adapter.ts index c4c8ad9f..cd5a5d8b 100644 --- a/src/test/adapter.ts +++ b/src/test/adapter.ts @@ -92,6 +92,16 @@ describe('PHP Debug Adapter', () => { client.waitForEvent('terminated'), ]) }) + ;(process.platform === 'win32' ? it.skip : it)('should error on existing unix pipe', async () => { + await assert.isRejected( + client.launch({ + program, + hostname: 'unix:///tmp', + runtimeArgs: ['-dxdebug.client_host=unix:///tmp'], + }), + /File .+ exists and cannot be used for Unix Domain socket/ + ) + }) }) describe('continuation commands', () => {