Skip to content

net/http: short writes with FileServer on macos #70000

Closed
@a-palchikov

Description

@a-palchikov

Go version

go version go1.23.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/user/Library/Caches/go-build'
GOENV='/user/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/user/dev/go/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/user/dev/go/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG='httpmuxgo121=0'
GOTELEMETRY='local'
GOTELEMETRYDIR='/user/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK='/user/dev/path/to/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/_y/<snip>/T/go-build<id>=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I have a small webserver that serves static files in a testing setup.

What did you see happen?

I'm on go 1.23.2 on macos 14.7 and I'm having issues with the stdlib http.FileServer.
After much of poking around, I found that with the BSD sendfile implementation in internal/poll/sendfile_bsd.go having
the maxSendfileSize set to 4MiB is causing all large file transfers to fail. For example, the following is the curl failure:

...
{ [512 bytes data]
* transfer closed with 361300436 bytes remaining to read
  1  350M    1 5567k    0     0  80.7M      0  0:00:04 --:--:--  0:00:04 81.1M
* Closing connection
curl: (18) transfer closed with 361300436 bytes remaining to read

so all requests are failing with short writes.

If I update the maxSendfileSize to maximum (adopting the change from this commit) I don't observe any failures.

Just setting the maxSendfileSize feels like a hack though (maybe I'm wrong) so I'd appreciate any hints on this behavior.

What did you expect to see?

The sendfile API should be able to send files in their entirety.

Metadata

Metadata

Assignees

Labels

NeedsFixThe path to resolution is known, but the work has not been done.OS-Darwin

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions