fix: clear CDP proxy startup error listener (#2876)
This commit is contained in:
parent
3134496a6d
commit
57990fdcf3
|
|
@ -94,6 +94,14 @@ describe('CdpWsProxy', () => {
|
|||
expect(proxy.getPort()).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('does not retain an extra startup server error listener after binding', () => {
|
||||
const server = (
|
||||
proxy as unknown as { httpServer: { listenerCount: (event: string) => number } }
|
||||
).httpServer
|
||||
|
||||
expect(server.listenerCount('error')).toBeLessThanOrEqual(1)
|
||||
})
|
||||
|
||||
it('attaches debugger on start', () => {
|
||||
expect(mock.webContents.debugger.attach).toHaveBeenCalledWith('1.3')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ export class CdpWsProxy {
|
|||
return new Promise<string>((resolve, reject) => {
|
||||
this.httpServer = createServer((req, res) => this.handleHttpRequest(req, res))
|
||||
this.wss = new WebSocketServer({ server: this.httpServer })
|
||||
const onListenError = (error: Error): void => {
|
||||
reject(error)
|
||||
}
|
||||
this.wss.on('connection', (ws) => {
|
||||
if (this.client) {
|
||||
this.client.close()
|
||||
|
|
@ -37,6 +40,7 @@ export class CdpWsProxy {
|
|||
})
|
||||
})
|
||||
this.httpServer.listen(0, '127.0.0.1', () => {
|
||||
this.httpServer?.removeListener('error', onListenError)
|
||||
const addr = this.httpServer!.address()
|
||||
if (typeof addr === 'object' && addr) {
|
||||
this.port = addr.port
|
||||
|
|
@ -45,7 +49,7 @@ export class CdpWsProxy {
|
|||
reject(new Error('Failed to bind proxy server'))
|
||||
}
|
||||
})
|
||||
this.httpServer.on('error', reject)
|
||||
this.httpServer.once('error', onListenError)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue