Skip to content

Conversation

@ferhatelmas
Copy link
Contributor

fixes #1320

Copy link
Member

@Acconut Acconut left a 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.

Comment on lines 36 to 45
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(),
Copy link
Member

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:

Suggested change
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,

Copy link
Contributor Author

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) {
Copy link
Member

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.

Copy link
Contributor Author

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.

@Acconut Acconut changed the title handler: fix race for progress hook handler: fix panic in hook emitting logic Jan 14, 2026
Copy link
Member

@Acconut Acconut left a 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!

@Acconut Acconut merged commit 8bbe65e into tus:main Jan 14, 2026
7 checks passed
@ferhatelmas ferhatelmas deleted the hook-race branch January 15, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tusd Panic with Creation-With-Upload

2 participants