🚱 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

@@ -57,3 +57,16 @@ describe "Task", ->
expect(deprecations.length).toBe 1
expect(deprecations[0].getStacks()[0][1].fileName).toBe handlerPath
jasmine.restoreDeprecationsSnapshot()
it "adds data listeners to standard out and error to report output", ->
task = new Task(require.resolve('./fixtures/task-spec-handler'))
{stdout, stderr} = task.childProcess
task.start()
task.start()
expect(stdout.listeners('data').length).toBe 1
expect(stderr.listeners('data').length).toBe 1
task.terminate()
expect(stdout.listeners('data').length).toBe 0
expect(stderr.listeners('data').length).toBe 0

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