Glimpse / Home

Project Glimpse: Node Edition - Spend less time debugging and more time developing.
http://node.getglimpse.com
Other
252 stars 9 forks source link

[HAPI] Can't set headers after they are sent #95

Closed AdriVanHoudt closed 7 years ago

AdriVanHoudt commented 7 years ago

I'm getting this error on trying glimpse out. Using node 7.10.0 on latests mac but the cause is probably the usage of hapi

Error: Can't set headers after they are sent.
     at SendStream.headersAlreadySent (/Users/[directory]/node_modules/send/index.js:326:13)
     at SendStream.send (/Users/[directory]/node_modules/send/index.js:525:17)
     at onstat (/Users/[directory]/node_modules/send/index.js:624:10)
     at wrappedCallback (/Users/[directory]/node_modules/@glimpse/glimpse-agent-node/release/async-track/async-track.js:293:33)
     at FSReqWrap.oncomplete (fs.js:114:15)
mike-kaufman commented 7 years ago

Thanks Adri - can you point us to a sample project where we can reproduce this?

AdriVanHoudt commented 7 years ago

I tested this with the company server project which does a bunch of stuff but let me see what I can do

AdriVanHoudt commented 7 years ago

This gist (https://gist.github.com/AdriVanHoudt/616f7fdcd4c9334e742c6fd8b705dfd1) results in the error when going to the url that Glimpse prints.

I think this has to do with Glimpse trying to run on the same uri and port as the server and hapi routing blocks this since the Glimpse route is not registered in hapi's routing table and thus gives a 404.

I hopes this helps, I know hapi is not officially supported so...

mike-kaufman commented 7 years ago

great, thanks for the repro Adri! Our intention with Hapi is that we don't yet provide deep insights (e.g., understanding middleware pipeline), but we'd like for basics to work. I'll take a quick look at what's going on.

AdriVanHoudt commented 7 years ago

Yeah I didn't expect that either since it is not 'supported' but I thought it would just plug into the http module :P if I can help with any hapi related stuff/questions please do let me know!

nikmd23 commented 7 years ago

Thanks for submitting this issue @AdriVanHoudt.

Since you mentioned that your willing to answer Hapi related questions, I'd love to take you up on it - though this probably isn't the right place. Would you mind shooting me an email? nik.molnar@microsoft.com

AdriVanHoudt commented 7 years ago

@nikmd23 if these are general question feel free to open an issue over at https://github.com/hapijs/discuss/issues (some even more knowledgeable people can help answer there ;) ) otherwise shoot questions at adri@salesflare.com

philliphoff commented 7 years ago

@AdriVanHoudt: I've submitted a PR intended to resolve some of the issues found when using Glimpse with Hapi; we'll let you know when it works its way into an upcoming release.

avanderhoorn commented 7 years ago

To provide an update... for those interested, here are some technical details on the issue from @philliphoff:

The issue stems from an assumption (that holds true for Express) that the application framework's entry point is a callback passed to createServer(). Hapi, on the other hand, instead directly subscribes to request events via server.on(). This resulted in two issues:

  • In Glimpse, both Hapi and Glimpse were independently handling Glimpse endpoint requests as they were both subscribed to the request event, resulting in race conditions when sending responses (as Hapi, not seeing those endpoints in any registered route, would generate a default Not Found response).

As @philliphoff said, patch is going through, PR and testing atm.

AdriVanHoudt commented 7 years ago

👌 could you link the PR, curious to take a look ^^

philliphoff commented 7 years ago

The repo for the actual Glimpse Node agent/server package is currently private, unfortunately.

AdriVanHoudt commented 7 years ago

ah np, looking forward to try it!

mike-kaufman commented 7 years ago

We just released a fix to npm in glimpse version v0.20.9 that addresses this issue. If you're still having problems w/ hapi, please let us know!

Thanks!

AdriVanHoudt commented 7 years ago

I can confirm it is working now! (I had an ssl error but nothing special) It does seem it does not handle gzip response data to well. Also it seems to miss a bunch of analytics but I assume this is due to the basic hapi support for the moment

Thanks again for fixing this! 🔥

avanderhoorn commented 7 years ago

@AdriVanHoudt what is the SSL error you are seeing and what are you noticing around gzip responses? Are you seeing HUD embedded in your page? If not, until our next release (where you wont need to do this anymore) you can get HUD showing up by following this - http://node.getglimpse.com/docs/setup/getting-started/#how-do-i-manually-inject-the-abbr-title-heads-up-display-hud-abbr-and-browser-agent-into-my-site. It walks you through how to include it and the browser agent manually. Ensuring that the browser agent is included will also help fill gaps in the timing data, light up resource details and allow us to observe fetch/ajax requests.

Additionally, I'd be interested to know what hapi specific insights you would like to see and what priority you would put on them if you had $100 to spend on getting them done - @AdriVanHoudt @YoannMa

AdriVanHoudt commented 7 years ago

The ssl thing was my own fault :D Btw I'm running a pure API with hapi so no client

This is what I see in the response tab https://puu.sh/vRS8F/e8726d1d22.png https://puu.sh/vRS9P/203c658c39.png

What I mean by missing is that the middleware and resources are always empty https://puu.sh/vRSaW/b23cdcf59e.png and also some timing stuff https://puu.sh/vRSer/7e4b39044d.png

I think just seeing the current stuff work out of the box with hapi would be great 🙏

I hope this helps

YoannMa commented 7 years ago

Got the same problem about the gzip not parsed.

One of my co-worker couldn't make it work with his own Hapi but I think it's something else, i'll investigate on it.

And about hapi specific insights, I feel like @AdriVanHoudt just seeing Glimpse works with Hapi without missing data would be awesome.

I don't use Hapi as a content delivery so I don't intend to use the embedded HUD.

I don't know if it's related to Hapi, but the button on top right to select the latest request doesn't seem to work, maybe @AdriVanHoudt could try it too ;) .

image (screenshot from the doc)

avanderhoorn commented 7 years ago

@YoannMa @AdriVanHoudt Thanks so much for the context!

Since your are predominantly used for serving data (i.e. web api's) some of Glimpse's features won't light up. Specifically the "Resources" section at the bottom of the "Request" tab and the "Detailed" timing info in the overview section. The former doesn't really make sense for a Web API and the later is because the server currently provides us with that data (hence because there is no browser we can't give you that timing breakdown). To help make this less confusion, both these sections will be hidden as of our next release for cases where its not relevant.

As for that top button, its "Follow mode" its currently not that well documented, but it's design to stay in lock step with the browser as the user navigates along. In the case of a web api, there isn't really anything to follow along with. Exactly what we do in the case of web apis is a good question. When selected we could just follow all requests, but there is also the question of "how do we know if this is a web api app and hence the behavior should change". Any thoughts of what you would expect to see in this case?

YoannMa commented 7 years ago

Well I understand better this feature follow mode and I agree with you that you can't know if it's a Web API or not, unless you specified it on the config, but it doesn't feel right I think to change the behavior of this feature if it's a Web API. It's just maybe that name/description wasn't explicit as first maybe (and as you said, not that well documented).

Now, is the feature "to follow the last request made" really useful ? It's another subject i guess.

I think the most important data would be the "Timeline chart" with data about Hapi itself and other middleware/plugins used.

AdriVanHoudt commented 7 years ago

@avanderhoorn the resources and timing missing makes sense and 👍 on hiding when not relevant. This still leaves the middleware tab. Are you patching express specific middleware? I can give you some tracing examples which traces stuff like mysql and redis in general if you'd like. (Assuming this is what that section would show :P)

YoannMa commented 7 years ago

Hi again, I think I found out why my co-worker couldn't make it works with his Hapi, it was because of websocket, he uses https://github.com/sibartlett/hapi-io.

I didn't found any websocket in Glimpse so i don't know why it doesn't work.