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

Fix async wrap http #4509

Closed
wants to merge 2 commits into from
Closed

Conversation

indutny
Copy link
Member

@indutny indutny commented Jan 1, 2016

Do not go through async wrap hooks if we are already within the
`MakeCallback`. This commit allows calling `MakeCallback` recursively.
Make `HTTPParser` an instance of `AsyncWrap` and make it use
`MakeCallback`. This means that async wrap hooks will be called on
consumed TCP sockets as well as on non-consumed ones.

Fix: nodejs#4416
@trevnorris
Copy link
Contributor

Doesn't address node::MakeCallback(). Also the prevention of reentry should technically be addressed by the in_tick() call below. Except there's a bug using SetVerbose() which never allows those to run in case of an error. I have a work in progress fix #4507 but some tests are still failing.

Switching to use AsyncWrap and adding the HTTP provider is nice. Sure some developers will enjoy seeing that information.

@indutny
Copy link
Member Author

indutny commented Jan 1, 2016

Preemption won't be fixed by in_tick(), as far as I can see. in_tick guards only tick callback, and won't guard any other cbs invoked.

@JungMinu JungMinu added the lib / src Issues and PRs related to general changes in the lib or src directory. label Jan 2, 2016
@trevnorris
Copy link
Contributor

@indutny Do you mean that neither the domain nor async callbacks should run in the case of nested MakeCallback() calls?

@indutny
Copy link
Member Author

indutny commented Jan 2, 2016

Mmm... I don't know, technically there is no point in reporting it, or is there?

@@ -33,6 +33,7 @@ namespace node {
V(UDPWRAP) \
V(UDPSENDWRAP) \
V(WRITEWRAP) \
V(HTTP) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind changing this to HTTPPARSER (that's exactly what it's being used for right?) and also ordering it alphabetically?

@trevnorris
Copy link
Contributor

Even if the MakeCallback call is nested, I'm not sure it's correct that the domain enter() function doesn't run. It should still effectively be it's own execution stack (if that makes sense), right?

@indutny
Copy link
Member Author

indutny commented Jan 5, 2016

I have totally no idea how it should work. cc @misterdjules maybe?

@trevnorris
Copy link
Contributor

@indutny @misterdjules responded in #4507 (comment) in more detail about how domains should work in MakeCallback. I changed my PR to match his information, and provided an explanation below.

@ofrobots I'm not sure AsyncCallbackScope is needed. Going to do some testing against my linked PR above and see if the issue has been resolved.

@misterdjules
Copy link

@trevnorris My comment at #4507 (comment) was more a set of questions that came up to mind when reading the changes in #4507 than an authoritative answer. I still haven't had the time to make up my mind on what is the proper way to answer these questions.

@misterdjules
Copy link

@indutny @trevnorris I would think that entering the domain in a nested synchronous node::*::MakeCallback call is useless, since it would enter the same domain as its caller.

The reason why it's useful to call Domain.prototype.enter in the node::*::MakeCallback root call is that it's always (at least for now) a call that is made asynchronously, and thus at that point all active domains have exited, including the domain within which the callback was scheduled. That domain needs to be reentered.

For instance in the following code snippet:

var domain = require('domain');

var d = domain.create();
d.run(function() {
  setImmediate(foo() { throw new Error('boom'); });
});

by the time foo is called by node::MakeCallback, domain d exited, and needs to be re-entered. If the node::MakeCallback call that called foo was re-entered, that domain would already be on the domains stack and would already be the active domain, so there would be no need to enter it.

However, if for some reason you make the decision to re-enter the domain in that case , it needs to be exited. Basically it's either entering and exiting in nested calls, or not doing any of them.

I hope that makes sense and that helps.

@trevnorris
Copy link
Contributor

@indutny PING PING PING

@AndreasMadsen
Copy link
Member

@trevnorris took over this PR and created #5419, it landed a month ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants