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

Implement hijacker interface for Negroni integration #871

Merged
merged 4 commits into from
Sep 3, 2024

Conversation

ribice
Copy link
Collaborator

@ribice ribice commented Aug 12, 2024

Resolves #837 (comment)

@ribice ribice requested a review from cleptric August 12, 2024 14:43
Copy link

codecov bot commented Aug 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.81%. Comparing base (11d3c79) to head (e7df055).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #871      +/-   ##
==========================================
- Coverage   82.83%   82.81%   -0.03%     
==========================================
  Files          51       51              
  Lines        4597     4580      -17     
==========================================
- Hits         3808     3793      -15     
+ Misses        636      633       -3     
- Partials      153      154       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@cleptric cleptric left a comment

Choose a reason for hiding this comment

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

There are some breaking changes in here we need to call out on the changelog. Besides this, LGTM!

@ribice
Copy link
Collaborator Author

ribice commented Aug 15, 2024

There are some breaking changes in here we need to call out on the changelog. Besides this, LGTM!

Are you referring to moving the WrapResponseWriter from sentryhttp to sentry?

That wasn't supposed to be exposed externally, so doubt anyone used it. To prevent a breaking change, we can keep it at sentryhttp as well (and just call the one at sentry internally)?

@cleptric
Copy link
Member

It’s ok, we just need to call it out 🙂

@ribice ribice requested a review from cleptric August 17, 2024 06:06
@ribice
Copy link
Collaborator Author

ribice commented Aug 28, 2024

@cleptric Perhaps we should move the Hijacker interface to /internal?

@aldy505
Copy link
Contributor

aldy505 commented Aug 30, 2024

Perhaps we should move the Hijacker interface to /internal?

@ribice I'd say you should move it to internal package, but keep the one at sentryhttp to avoid breaking change, then add DEPRECATION notice (the one that's according to godoc format).

The one on sentryhttp should be a passthrough to internal package. Then after 2-3 minor version release, you can safely remove it.

@cleptric cleptric merged commit e5d46d5 into master Sep 3, 2024
22 checks passed
@cleptric cleptric deleted the negroni-hijacker branch September 3, 2024 10:19
@kydemy-fran
Copy link

kydemy-fran commented Sep 19, 2024

Hi there,
I reported the originar issue with negroni + websockets: the response writter does not implement http.Hijacker interface. #837 (comment)
Today we have upgraded from v0.27.0 to v0.29.0 and the error persists.

I've reviewed the code and I've found the issue:

func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
_, fl := w.(http.Flusher)
bw := basicWriter{ResponseWriter: w, code: http.StatusOK}
if protoMajor == 2 {
_, ps := w.(http.Pusher)
if fl && ps {
return &http2FancyWriter{bw}
}
} else {
_, hj := w.(http.Hijacker)
_, rf := w.(io.ReaderFrom)
if fl && hj && rf {
return &httpFancyWriter{bw}
}
}
if fl {
return &flushWriter{bw}
}
return &bw
}

The w is of type *negroni.responseWriter in negroni v1, which is the one referenced by the sentry-go package.
This type implements http.Flusher, http.Hijacker, but not io.ReaderFrom.
So fl and hj are true, but rf is not. So in line 48 does not return the httpFancyWriter.
And it returns the basic flushWriter in line 53. (which does not support hijacker / websockets.

We have had to rollback our releases today as this was failing.

As mentioned before, negroni v1 uses a limited writer. This is solved in negroni v3, which is easy to migrate to, but it would be nice if go-sentry was upgraded to v3 too, as v1 was released in 2018. Having our project requiring both versions is a nightmare.

From my point of view, if go-sentry imports negroni v1, then the library should work with v1 (and this is not happening at the moment). If you expect people to be using v3 (which works with go-sentry v0.29.0) then you should import negroni v3 in your go.mod.

Please let me know your thoughts

Thank you!

@cleptric
Copy link
Member

@ribice can you take a look please?

@ribice
Copy link
Collaborator Author

ribice commented Sep 19, 2024

Yes I can. Before I change the interface to support v1, I'm curious if we can update to v3? Is that an option?

@cleptric
Copy link
Member

Fine with me.

@kydemy-fran
Copy link

Thank you for looking into this guys :)

@ribice
Copy link
Collaborator Author

ribice commented Sep 20, 2024

Upgraded negroni to latest version in #885. This worked just fine: https://gist.github.com/ribice/95934b3c209b9692efc4b50b91d5dd4a

@ribice
Copy link
Collaborator Author

ribice commented Oct 14, 2024

@kydemy-fran Can you confirm that it works as expected with 0.29.1?

@kydemy-fran
Copy link

Hi there @ribice and @cleptric.
I've just tested it and it seems to be working fine using the negroni v3 implementation.
Thank you for your help!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants