diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-26 11:11:46 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-26 11:11:52 +0200 |
commit | 706a450fe61c020bcad35ca9edf28dcc4bab14a0 (patch) | |
tree | 5309cafcd1164ab98da088c942e067bbf25254e1 | |
parent | 91ae3c4a5411629c6f09d04f1a6211812b8c0d6d (diff) | |
download | PeerTube-706a450fe61c020bcad35ca9edf28dcc4bab14a0.tar.gz PeerTube-706a450fe61c020bcad35ca9edf28dcc4bab14a0.tar.zst PeerTube-706a450fe61c020bcad35ca9edf28dcc4bab14a0.zip |
Fix test event leak
-rw-r--r-- | shared/extra-utils/server/server.ts | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts index bc5e1cd5f..f7048ba43 100644 --- a/shared/extra-utils/server/server.ts +++ b/shared/extra-utils/server/server.ts | |||
@@ -221,11 +221,17 @@ export class PeerTubeServer { | |||
221 | 221 | ||
222 | this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions) | 222 | this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions) |
223 | 223 | ||
224 | const onExit = function () { | 224 | const onPeerTubeExit = () => rej(new Error('Process exited')) |
225 | return rej(new Error('Process exited')) | 225 | const onParentExit = () => { |
226 | if (!this.app || !this.app.pid) return | ||
227 | |||
228 | try { | ||
229 | process.kill(self.app.pid) | ||
230 | } catch { /* empty */ } | ||
226 | } | 231 | } |
227 | 232 | ||
228 | this.app.on('exit', onExit) | 233 | this.app.on('exit', onPeerTubeExit) |
234 | process.on('exit', onParentExit) | ||
229 | 235 | ||
230 | this.app.stdout.on('data', function onStdout (data) { | 236 | this.app.stdout.on('data', function onStdout (data) { |
231 | let dontContinue = false | 237 | let dontContinue = false |
@@ -254,16 +260,11 @@ export class PeerTubeServer { | |||
254 | if (options.hideLogs === false) { | 260 | if (options.hideLogs === false) { |
255 | console.log(data.toString()) | 261 | console.log(data.toString()) |
256 | } else { | 262 | } else { |
263 | process.removeListener('exit', onParentExit) | ||
257 | self.app.stdout.removeListener('data', onStdout) | 264 | self.app.stdout.removeListener('data', onStdout) |
258 | self.app.removeListener('exit', onExit) | 265 | self.app.removeListener('exit', onPeerTubeExit) |
259 | } | 266 | } |
260 | 267 | ||
261 | process.on('exit', () => { | ||
262 | try { | ||
263 | process.kill(self.app.pid) | ||
264 | } catch { /* empty */ } | ||
265 | }) | ||
266 | |||
267 | res() | 268 | res() |
268 | }) | 269 | }) |
269 | }) | 270 | }) |