Skip to content

Commit d93550f

Browse files
authored
fix: don't leak event listener in playwright provider (#9910)
1 parent 1bc3e63 commit d93550f

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

packages/browser-playwright/src/playwright.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,21 @@ export class PlaywrightBrowserProvider implements BrowserProvider {
136136
}
137137

138138
// make sure the traces are finished if the test hangs
139-
process.on('SIGTERM', () => {
140-
if (!this.browser) {
141-
return
142-
}
143-
const promises = []
144-
for (const [trace, contextId] of this.pendingTraces.entries()) {
145-
promises.push((() => {
146-
const context = this.contexts.get(contextId)
147-
return context?.tracing.stopChunk({ path: trace })
148-
})())
149-
}
150-
return Promise.allSettled(promises)
151-
})
139+
process.on('SIGTERM', this.onSIGTERM)
140+
}
141+
142+
private onSIGTERM = () => {
143+
if (!this.browser) {
144+
return
145+
}
146+
const promises = []
147+
for (const [trace, contextId] of this.pendingTraces.entries()) {
148+
promises.push((() => {
149+
const context = this.contexts.get(contextId)
150+
return context?.tracing.stopChunk({ path: trace })
151+
})())
152+
}
153+
return Promise.allSettled(promises)
152154
}
153155

154156
private async openBrowser(openBrowserOptions: { parallel: boolean }) {
@@ -545,6 +547,8 @@ export class PlaywrightBrowserProvider implements BrowserProvider {
545547
}
546548

547549
async close(): Promise<void> {
550+
process.off('SIGTERM', this.onSIGTERM)
551+
548552
debug?.('[%s] closing provider', this.browserName)
549553
this.closing = true
550554
if (this.browserPromise) {

0 commit comments

Comments
 (0)