You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a simple HTTPserver and connecting to it one looses the handle context. Meaning there is no way to know what handle or callback created the new handle.
Unfortunately getting around this requires knowing implementation details, but here's an example:
'use strict';consthttp=require('http');constasync_wrap=process.binding('async_wrap');constprint=process._rawDebug;letclient;functioninit(p,parent){if(parent)client=this;}functionnoop(){}async_wrap.setupHooks(init,noop,noop);async_wrap.enable();constserver=http.createServer(function(req,res){// Print if this client matches the init w/ parent.print(req.client._handle===client);res.end('hello world');});server.listen(0,'localhost',function(){// Disable listening to simply test.async_wrap.disable();http.get('http://localhost:'+server.address().port+'/',(res)=>{res.resume();res.once('end',()=>server.close());});});
This demonstrates that the client handle for a given http request can still be retrieved. Though this is not ideal. I'll look into propagating this information during the HTTPParser phase.
One issue with your test is that it will exit on cases like SHUTDOWNWRAP. May want to focus your test using .disable() like I have above.
One issue with your test is that it will exit on cases like SHUTDOWNWRAP. May want to focus your test using .disable() like I have above.
Sorry I don't follow you.
I don't understand your SHUTDOWNWRAP reference, could you provide an example.
I find that the first part of the test (https://gist.github.com/AndreasMadsen/f56bbdbcd18a2c6358f3#file-test_http-js-L7L52) i fairly generic. It just checks that there always is a callback or handle context for the new handle. I think that should always be the case, otherwise making a long-stack-trace tool would not be possible.
It should work the same as TCP if you listened for the http server's 'connection' event. Instead of the default 'request' event.
I think we are on the same page here, but just to be sure. One of my goals is to write a long-stack-trace tool, that doesn't require any extra interaction from the user except adding -r trace. Changing the the eventlistener from request to connection and feeding back the socket handle to the server handle, definitely qualifies as extra interaction.
Activity
trevnorris commentedon Oct 7, 2015
Unfortunately getting around this requires knowing implementation details, but here's an example:
This demonstrates that the client handle for a given http request can still be retrieved. Though this is not ideal. I'll look into propagating this information during the HTTPParser phase.
One issue with your test is that it will exit on cases like
SHUTDOWNWRAP. May want to focus your test using.disable()like I have above.trevnorris commentedon Oct 7, 2015
It should work the same as TCP if you listened for the http server's
'connection'event. Instead of the default'request'event.AndreasMadsen commentedon Oct 7, 2015
Sorry I don't follow you.
I don't understand your
SHUTDOWNWRAPreference, could you provide an example.I find that the first part of the test (https://gist.github.com/AndreasMadsen/f56bbdbcd18a2c6358f3#file-test_http-js-L7L52) i fairly generic. It just checks that there always is a callback or handle context for the new handle. I think that should always be the case, otherwise making a long-stack-trace tool would not be possible.
I think we are on the same page here, but just to be sure. One of my goals is to write a long-stack-trace tool, that doesn't require any extra interaction from the user except adding
-r trace. Changing the the eventlistener fromrequesttoconnectionand feeding back the socket handle to the server handle, definitely qualifies as extra interaction.AndreasMadsen commentedon Mar 4, 2016
Closed by #5419
trevnorris commentedon Mar 4, 2016
may need to reopen unless I can fix a regression the patch introduced...