-
Notifications
You must be signed in to change notification settings - Fork 528
handler: fix panic in hook emitting logic #1337
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
Conversation
Acconut
left a comment
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.
Thank you very for digging into this and finding the culprit! I just have two remarks and then we can merge this.
pkg/handler/hooks.go
Outdated
| c.req.Header.Set("Host", c.req.Host) | ||
|
|
||
| return HookEvent{ | ||
| Context: c, | ||
| Upload: info, | ||
| HTTPRequest: HTTPRequest{ | ||
| Method: c.req.Method, | ||
| URI: c.req.RequestURI, | ||
| RemoteAddr: c.req.RemoteAddr, | ||
| Header: c.req.Header, | ||
| Header: c.req.Header.Clone(), |
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.
It would be better if we don't modify the request header at all, but just add the Host entry to a copy for the hooks:
| Header: c.req.Header.Clone(), | |
| reqHeader := c.req.Header.Clone() | |
| reqHeader.Set("Host", c.req.Host) | |
| return HookEvent{ | |
| Context: c, | |
| Upload: info, | |
| HTTPRequest: HTTPRequest{ | |
| Method: c.req.Method, | |
| URI: c.req.RequestURI, | |
| RemoteAddr: c.req.RemoteAddr, | |
| Header: reqHeader, |
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.
I agree with that. I would even put it into a separate field so that we don't need to copy but it would be breaking change in serialization so for the fix, updated not to modify original headers.
| // This test will fail with `go test -race` if Header is not cloned. | ||
| // | ||
| // See: https://github.com/tus/tusd/issues/1320 | ||
| func TestHookEventHeaderRace(t *testing.T) { |
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.
Thank you for adding these tests as a demonstration. While they are useful now, I'm not sure if we should keep them in the repo after the fix is merged.
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.
IMO, they are useful to catch if there might be a regression. It doesn't complicate or slow down, better to keep but if you insist, I can drop so that we can merge.
fixes tus#1320 Signed-off-by: ferhat elmas <[email protected]>
82a8808 to
f73c97e
Compare
Acconut
left a comment
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.
Thank you very much!
fixes #1320