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

net/http: missing flush in http.ServeContent? Go 1.19.4 #57744

Closed
ivanjaros opened this issue Jan 11, 2023 · 3 comments
Closed

net/http: missing flush in http.ServeContent? Go 1.19.4 #57744

ivanjaros opened this issue Jan 11, 2023 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@ivanjaros
Copy link

ivanjaros commented Jan 11, 2023

I have updated my go to the latest version 1.19.4, I think from previous 1.19.3, and I have noticed that when files go over certain size(small test sample suggest this) the http.ServeContent will fail to serve them properly. Specifically, images will be missing ending and will look like this:
obrázok

and firefox will return Image corrupt or truncated.. PDF files will also fail to load. So it is universal issue. I have verified with io.Copy() instead of http.ServeContent that the file is correct. So the bug is in the http.ServeContent and it feels like there is some buffering/flushing issue, specifically because smaller images are fine but i think 64k is the line where above it the files will be corrupt. In the release notes there are couple of mentions of http package so it's almost certain there was a bug introduced as part of a fix of something else.

ps: go1.19.4 windows/amd64

@seankhliao
Copy link
Member

When was the last time this worked?
Please include a standalone reproducer, along with files you're serving, and how you're testing, preferably without needing to install a browser.

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 11, 2023
@seankhliao seankhliao changed the title Missing flush in http.ServeContent? Go 1.19.4 net/http: missing flush in http.ServeContent? Go 1.19.4 Jan 11, 2023
@ivanjaros
Copy link
Author

It worked yesterday before the update. I have added manual content type to the response header, so http.ServeContent does not have to do the mime sniff test and the issue disappeared.

@seankhliao seankhliao added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jan 11, 2023
@ivanjaros
Copy link
Author

I did a clean test and no issues. I'll close this for now, unless I'll get more details.

package main

import (
	"net"
	"net/http"
	"os"
	"time"
)

func main() {
	lis, _ := net.Listen("tcp", ":8099")
	defer lis.Close()

	muxer := func(w http.ResponseWriter, r *http.Request) {
		src, _ := os.Open("image.jpg")
		defer src.Close()
		http.ServeContent(w, r, "file", time.Time{}, src)
	}

	http.Serve(lis, http.HandlerFunc(muxer))
}

@golang golang locked and limited conversation to collaborators Jan 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants