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: hijack deadlock bug #18750

Closed
septs opened this issue Jan 22, 2017 · 11 comments

Comments

Projects
None yet
3 participants
@septs
Copy link

commented Jan 22, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8beta2 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/septs/.goenv"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build373922980=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

PoC
see https://play.golang.org/p/23AuanjGHM

What did you expect to see?

fix it

What did you see instead?

image

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 22, 2017

For questions about Go, see https://golang.org/wiki/Questions.

This just looks like a bug in your program. Your channel is unbuffered, so your dial never completes.

@bradfitz bradfitz closed this Jan 22, 2017

@septs septs changed the title hijack deadlock issuer net/http: hijack deadlock bug Jan 22, 2017

@Icenowy

This comment has been minimized.

Copy link

commented Jan 22, 2017

icenowy@x220i [ tmp ] $ go-gnu run poc.go 
hijack start
hijack done
fatal error: all goroutines are asleep - deadlock!

runtime stack:

	:0

	:0

	:0

	:0

	:0

	:0
main
	/var/lib/abbs/build/tmp.krByaGDdEY/gcc-6.2.0/libgo/runtime/go-main.c:55

	:0

	:0

	:0

goroutine 16 [select]:

	:0

	:0

	:0

	:0

	:0

	:0
main.main
	/tmp/poc.go:29

	:0

	:0

	:0

	:0
created by main
	/var/lib/abbs/build/tmp.krByaGDdEY/gcc-6.2.0/libgo/runtime/go-main.c:54

goroutine 17 [syscall]:
	goroutine in C code; stack unavailable

goroutine 18 [finalizer wait]:

	:0

	:0

	:0

	:0

goroutine 19 [GC sweep wait]:

	:0

	:0

	:0

	:0

goroutine 20 [chan receive]:

	:0
main.Accept.pN21_main.listenerWithPipe
	/tmp/poc.go:34

	:0

	:0

	:0

	:0

	:0
created by main.main
	/tmp/poc.go:19

goroutine 22 [semacquire]:

	:0

	:0

	:0

	:0

	:0

	:0

	:0

	:0

	:0

	:0

	:0

	:0

	:0

goroutine 23 [select]:

	:0

	:0

	:0

	:0

	:0

	:0
exit status 2
icenowy@x220i [ tmp ] ! go-gnu env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr"
GOTOOLDIR="/usr/lib/gcc/x86_64-aosc-linux-gnu/6.2.0"
GO15VENDOREXPERIMENT="1"
CC="/usr/bin/gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="/usr/bin/g++"
CGO_ENABLED="1"

Results on GCC Go.

@septs

This comment has been minimized.

Copy link
Author

commented Jan 22, 2017

Hijack is not used and does not cause problems
@bradfitz see https://play.golang.org/p/XgZwSOs6W3

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 22, 2017

The bug in your code I mentioned above still remains in your code.

Please take this to a forum. This isn't a bug in Go.

@septs

This comment has been minimized.

Copy link
Author

commented Jan 22, 2017

Your channel is unbuffered, so your dial never completes.

https://play.golang.org/p/vUcIHQ9Lyu
@bradfitz not is channel issue

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 22, 2017

Well you hijack the connection and then never do anything with it, ignoring the return result, so of course nothing happens. The client is deadlocked waiting for a result that will never come.

Please take this to a mailing list.

This is a bug in your program.

@septs

This comment has been minimized.

Copy link
Author

commented Jan 22, 2017

package main

import (
	"net"
	"net/http"
)

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/hijack", func(rw http.ResponseWriter, r *http.Request) {
		println("hijack start")
		conn, buf, err := rw.(http.Hijacker).Hijack()
		println(conn, buf, err)
		println("hijack done")
	})
	go http.ListenAndServe("127.0.0.1:9999", mux)
	client := &http.Client{
		Transport: &http.Transport{Dial: net.Dial},
	}
	client.Get("http://127.0.0.1:9999/hijack")
}

do not use net.Pipe()

➜  poc git:(master) ✗ go run poc2.go
hijack start
(0x7a6700,0xc4200fe000) 0xc4200ee090 (0x0,0x0)
hijack done
@septs

This comment has been minimized.

Copy link
Author

commented Jan 22, 2017

through net.Pipe() can not run to println("hijack done")

@septs

This comment has been minimized.

Copy link
Author

commented Jan 22, 2017

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 22, 2017

You don't understand how Hijack works. Please use a forum.

I don't provide technical support in the bug tracker.

Again, for questions about Go, see https://golang.org/wiki/Questions.

@golang golang locked and limited conversation to collaborators Jan 22, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.