mirror of
https://github.com/atom/atom.git
synced 2026-01-14 09:27:57 -05:00
🚱 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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user