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/fcgi: deadlock during write (regression in 1.16beta1) #43901

Closed
tdanecker opened this issue Jan 25, 2021 · 3 comments
Closed

net/http/fcgi: deadlock during write (regression in 1.16beta1) #43901

tdanecker opened this issue Jan 25, 2021 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@tdanecker
Copy link

tdanecker commented Jan 25, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16beta1 linux/amd64

Does this issue reproduce with the latest release?

This is a regression in 1.16beta1 introduced via https://go-review.googlesource.com/c/go/+/252417
It would be fixed by https://go-review.googlesource.com/c/go/+/275692

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16beta1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/app/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1261813594=/tmp/go-build -gno-record-gcc-switches"

What did you do?

When using fcgi behind nginx, writes to the ResponseWriter block because a mutex is still held by the goroutine serving the fcgi-child (https://github.com/golang/go/blob/master/src/net/http/fcgi/child.go#L174).

main.go:

package main

import (
	"fmt"
	"log"
	"net"
	"net/http"
	"net/http/fcgi"
)

func handler(w http.ResponseWriter, req *http.Request) {
	// the following write will block
	_, err := fmt.Fprintln(w, "test")
	if err != nil {
		log.Println(err)
	}
}

func main() {
	listener, err := net.Listen("tcp", ":9000")
	if err != nil {
		log.Fatalln(err)
	}
	err = fcgi.Serve(listener, http.HandlerFunc(handler))
	if err != nil {
		log.Fatalln(err)
	}
}

nginx.conf:

server {
    location / {
        include /etc/nginx/fastcgi.conf;
        fastcgi_pass localhost:9000;
    }
}

For a full, runnable example see fcgi_regression.zip

What did you expect to see?

$ curl localhost
test

What did you see instead?

$ curl localhost
<html>
<head><title>504 Gateway Time-out</title></head>
<body>
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx/1.19.6</center>
</body>
</html>

The server blocks and nginx returns a 504 Gateway Timeout after some time.

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Jan 25, 2021
@bcmills bcmills added this to the Go1.16 milestone Jan 25, 2021
@bcmills
Copy link
Contributor

bcmills commented Jan 25, 2021

CC @tz70s @odeke-em @bradfitz @golang/release

@odeke-em
Copy link
Member

Thanks for the report @tdanecker, and thanks for the ping and triage @bcmills! It is too late in the cycle so I’ll lean towards a revert; my apologies for the regression.

@gopherbot
Copy link

Change https://golang.org/cl/275692 mentions this issue: net/http/fcgi: remove locking added to prevent a test-only race

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 26, 2021
@golang golang locked and limited conversation to collaborators Jan 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants