Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call streams end to trigger cleanup (fix #62) #63

Merged
merged 1 commit into from
Sep 3, 2013
Merged

Call streams end to trigger cleanup (fix #62) #63

merged 1 commit into from
Sep 3, 2013

Conversation

danielchatfield
Copy link
Collaborator

From #62

cleanup isn't being called. It is called automatically when:

  • the end event is emitted on the source
    • the close event is emitted on the source
    • the close event is emitted on the destination

Since the destination is process.stdout we can't close that. We close the readline interface but this does not close the input or the output streams so cleanup is never fired.

To fix this leak we need to call mute-stream's end method.

By adding this.rl.output.end(); the above test doesn't fail (but it currently causes other tests to fail). I'm investigating the other tests now (at least one of them I can see is because we overwrite the output stream with something that doesn't have an end method).

Patch includes a change to the test to prevent a regression, ideally I'd want to add a separate test that catches any sort of memory leak but currently the node warning is just a console.error call so I can't see a way of "catching" it to fail the test.

// cc: @SBoudrias

@danielchatfield
Copy link
Collaborator Author

It would need more than just "catching" the console.error as the memory leek doesn't occur in the tests as the ReadlineStub doesn't register the event listeners that cause the leak.

@SBoudrias
Copy link
Owner

Maybe we could keep a count of the listeners added/removed on the Readline stub to see if there's any leakage.

But I think we should rethink how the stub works as the same trouble you have to add a test for this leak is the same as #59

I'll merge and push a patch in the next couple minutes.

SBoudrias added a commit that referenced this pull request Sep 3, 2013
Call streams end to trigger cleanup (fix #62)
@SBoudrias SBoudrias merged commit 7b433c7 into SBoudrias:master Sep 3, 2013
@danielchatfield
Copy link
Collaborator Author

@SBoudrias In this particular case the event listeners that were causing the problem were on process.stdout, not the readline and since the stub doesn't connect any of that stuff the memory leak doesn't actually occur in the test suite.

I think the stub is pretty convenient but we also need tests to make sure the readline interface is behaving properly as currently that can break and I'm not sure the tests would catch it.

@SBoudrias
Copy link
Owner

Yeah, I was thinking about a more complete readline stub with readable/writable streams in places of stdin and stdout - or even a real readline with stubbed Streams.

I just moved last weekend, so I don't have much time to dig this deeper, but I'll do in the next couple weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants