Skip to content

TestServesAShareThroughCaddy races under -race (also on main) #100

Closed

Description

@omarabulkhair-66

What

TestServesAShareThroughCaddy (internal/web/share_serve_test.go) sometimes fails under -race with "race detected during execution of test". It does so on main too, so it isn't tied to any PR.

How to reproduce

go test -race -count=30 -run TestServesAShareThroughCaddy ./internal/web

On main (fb62bf9), macOS arm64: 2 of 30 runs report a data race. In CI it failed the Go tests (Linux arm64) job on #87: https://github.com/flock-php/flock/actions/runs/41722049277

What the race report shows

The read is in Caddy's reverse_proxy (modules/caddyhttp/reverseproxy/reverseproxy.go:1368, via net/http/server.go:1145) while it serves the share's request through php_fastcgi. The call chain passes through flock/internal/web.shareHandler.ServeHTTP (internal/web/share.go:140), under encode and headers. The other side of the race is in the same request's handling.

So the share handler's response-writer wrapping (the Vite tag rewrite) and Caddy's proxy look like they touch the same request or response state from two goroutines.

Possible cause

The rewrite in shareHandler may read or replace the response writer (or the request's headers) while reverse_proxy is still streaming in another goroutine, e.g. the buffered writer being inspected before the upstream copy has finished. A first step would be the full race report from -race -count=30 with GORACE=halt_on_error=1.

I'm happy to dig into it if this fits.

Activity

  1. added
    help wanted
    and removed on Nov 4, 2026
  2. omarabulkhair-66 commented on Nov 4, 2026

    @omarabulkhair-66
    ContributorAuthor

    Fix in #102: the handler now gets its own copy of the headers while a page is rewritten, so reverse_proxy's trailers no longer touch the response from another goroutine. It comes with a test that catches the race every run without the fix.

  3. added a commit that references this issue on Nov 7, 2026
    28bf670
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

help wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions