🚱 Prevent stdout/stderr data listener leaks

Old listeners were not cleaned up before new ones were being added
causing the following console message:

warning: possible EventEmitter memory leak detected.

Refs #7033
This commit is contained in:
Kevin Sawicki
2015-06-01 09:35:41 -07:00
parent adc08d31d6
commit eaaa6b15e5
2 changed files with 20 additions and 4 deletions

View File

@@ -100,11 +100,12 @@ class Task
@childProcess.removeAllListeners()
@childProcess.on 'message', ({event, args}) =>
@emit(event, args...) if @childProcess?
# Catch the errors that happened before task-bootstrap.
@childProcess.stdout.on 'data', (data) ->
console.log data.toString()
@childProcess.stderr.on 'data', (data) ->
console.error data.toString()
@childProcess.stdout.removeAllListeners()
@childProcess.stdout.on 'data', (data) -> console.log data.toString()
@childProcess.stderr.removeAllListeners()
@childProcess.stderr.on 'data', (data) -> console.error data.toString()
# Public: Starts the task.
#
@@ -152,6 +153,8 @@ class Task
return unless @childProcess?
@childProcess.removeAllListeners()
@childProcess.stdout.removeAllListeners()
@childProcess.stderr.removeAllListeners()
@childProcess.kill()
@childProcess = null