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

tls: follow up for #5168 #5169

Closed
wants to merge 3 commits into from

Conversation

indutny
Copy link
Member

@indutny indutny commented Feb 9, 2016

This is a promised follow-up for #5168 PR.

cc @nodejs/crypto

R = @bnoordhuis

Invoke `close_cb` on `~StreamResource`, it will be used to unconsume
streams on destruction.
When parent stream is destroyed - remove references to it, and error
when attempting to access its properties.
@indutny
Copy link
Member Author

indutny commented Feb 9, 2016

@mscdex mscdex added tls Issues and PRs related to the tls subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. labels Feb 9, 2016
@bnoordhuis
Copy link
Member

src/stream_base.h:114: The class StreamResource probably needs a virtual destructor due to having virtual method(s), one declared at line 151. [runtime/virtual] [4]

EDIT: 6807dc1 fixes that.

@bnoordhuis
Copy link
Member

Adding nullptr checks everywhere is often an indication that one needs to rethink their object life cycle management... IOW, is this really the best possible fix?

@indutny
Copy link
Member Author

indutny commented Feb 16, 2016

@bnoordhuis yeah, there are conceptual problems that I haven't really figured out a best solution for yet. Perhaps, we could try to brainstorm it here together?

So basically the current scheme involves two objects: TLSWrap and TCPWrap that depend on each other. The bad thing is that they have different lifetime: TCPWrap::Close (inherited from HandleWrap) destroys the TCPWrap instance asynchronously, and TLSWrap is left with a dangling pointer to TCPWrap.

Why is cross-reference even needed? This is the way StreamBase works: there are callbacks and methods on TCPWrap instance. So in order to parse and override its input, one need to be able to listen for all data events (with OnRead and OnAlloc), and re-emit proper data events too (with tcpwrap->EmitData).

So the solution should either be re-thinking the StreamBase, making their lifetimes match, or adding close callback as in this PR.

I have no ideas for StreamBase re-thinking, it seems that matching lifetimes will very likely kill the reason why TCPWrap::Close deallocates TCPWrap (decrease memory consumption early), so I just did it as in this PR.

@bnoordhuis do you have any ideas?

@jasnell
Copy link
Member

jasnell commented Mar 21, 2016

@bnoordhuis ... ping

@bnoordhuis
Copy link
Member

No concrete suggestions, but I suspect a more rigorous refactoring is in order. This PR is really just a band-aid; it might be a quick fix but piling on workarounds doesn't result in maintainable software.

@jasnell
Copy link
Member

jasnell commented Feb 28, 2017

ping @indutny ... do you still want to pursue this?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Mar 1, 2017
@fhinkel
Copy link
Member

fhinkel commented Mar 26, 2017

Feel free to reopen this PR if you get back to working on it.

@fhinkel fhinkel closed this Mar 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. stalled Issues and PRs that are stalled. tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants