-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
async_wrap: WIP/Experiment, init/destroy HTTPParser on each use #5573
Conversation
Excellent. This is on my todo list. Here are a few things that need to be addressed:
The other use case for this are timers. Multiple JS timer instances are stored on a single |
Thanks for following up - good to hear it's not completely off base. The destructor is still in place, although the diff makes the change a little non-obvious. Good call about not initting/destroying, while consumers should be able to manage the handle reuse, two init callbacks "back-to-back" for the same handle is reasonably poor behaviour. Sounds like we just need to figure out a nice way to indicate "don't manage lifecycle events" - I'll play around with it. |
Some objects, such as HttpParser or TimerWrap, are repurposed across distinct usages of them to avoid construction/destruction churn. As such, while calling init/destroy callbacks on construction and destruction makes sense from an object lifecycle standpoint, it doesn't for what AsyncWrap is actually trying to achieve. This allows such objects to manually handle the init/destroy timing.
be1578b
to
64082db
Compare
Updated with super-basic flagging off init/destroy within constructor/destructor. Maybe not the nicest interface - and it would probably need to be extended up to HandleWrap as well, which isn't very nice. (As is, |
@@ -457,6 +457,7 @@ class Parser : public AsyncWrap { | |||
// Should always be called from the same context. | |||
CHECK_EQ(env, parser->env()); | |||
parser->Init(type); | |||
parser->InitAsyncWrap(env, args.This(), AsyncWrap::PROVIDER_HTTPPARSER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we have some way to access parent
at this point, that we could start providing it through the Init
?
Presently, if you disable async_wrap, you don't see the HTTPParser come through, because our parent is null. If we could tie it to the parent server, it would respect the rules a bit better.
shrug
Should the |
@AndreasMadsen You're correct. I have an implementation of this in a local branch while I work out the timer implementation details. It's basically @omsmith There are several issues with how
This shows that the correct parent (i.e. the connection) is not active and cannot propagate to the parser. These issues are all loosely related. |
7da4fd4
to
c7066fb
Compare
c133999
to
83c7a88
Compare
Wasn't sure the best place to have this discussion, so I went with opening a PR and figure it can be closed.
Been working with
AsyncWrap
a bit and it was very cool to see a7e49c8 land the other day :). Was playing with the following, which I know is probably horrible, of firing theinit
anddestroy
hooks per usage of theHTTPParser
, giving a clear parent/child relationship per-request, while still being able to reuse the actually instances.Just wanted to get thoughts on the concept, @trevnorris