mirror of
https://github.com/golang/go
synced 2024-11-11 21:10:21 -07:00
net/http/fcgi: Remove locks that were added to prevent a fake race
This reverts CL252417. Reason for revert: The race detector found a race only because the ReadWriter used in test code happened to be a bytes.Buffer whose Read() and Write() operate (unsafely) on shared state. This is not the case in any realistic scenario where the FastCGI protocol is spoken over sockets or pairs of pipes. Since tests that use nopWriteCloser don't care about any output generate by child.Serve(), we change nopWriteCloser to provide a dummy Write method.
This commit is contained in:
parent
3b2a578166
commit
b06d8377fd
@ -171,12 +171,9 @@ func (c *child) serve() {
|
|||||||
defer c.cleanUp()
|
defer c.cleanUp()
|
||||||
var rec record
|
var rec record
|
||||||
for {
|
for {
|
||||||
c.conn.mutex.Lock()
|
|
||||||
if err := rec.read(c.conn.rwc); err != nil {
|
if err := rec.read(c.conn.rwc); err != nil {
|
||||||
c.conn.mutex.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.conn.mutex.Unlock()
|
|
||||||
if err := c.handleRecord(&rec); err != nil {
|
if err := c.handleRecord(&rec); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,11 @@ var cleanUpTests = []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type nopWriteCloser struct {
|
type nopWriteCloser struct {
|
||||||
io.ReadWriter
|
io.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nopWriteCloser) Write(buf []byte) (int, error) {
|
||||||
|
return len(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nopWriteCloser) Close() error {
|
func (nopWriteCloser) Close() error {
|
||||||
@ -235,7 +239,7 @@ func TestChildServeCleansUp(t *testing.T) {
|
|||||||
for _, tt := range cleanUpTests {
|
for _, tt := range cleanUpTests {
|
||||||
input := make([]byte, len(tt.input))
|
input := make([]byte, len(tt.input))
|
||||||
copy(input, tt.input)
|
copy(input, tt.input)
|
||||||
rc := nopWriteCloser{bytes.NewBuffer(input)}
|
rc := nopWriteCloser{bytes.NewReader(input)}
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
c := newChild(rc, http.HandlerFunc(func(
|
c := newChild(rc, http.HandlerFunc(func(
|
||||||
w http.ResponseWriter,
|
w http.ResponseWriter,
|
||||||
@ -325,7 +329,7 @@ func TestChildServeReadsEnvVars(t *testing.T) {
|
|||||||
for _, tt := range envVarTests {
|
for _, tt := range envVarTests {
|
||||||
input := make([]byte, len(tt.input))
|
input := make([]byte, len(tt.input))
|
||||||
copy(input, tt.input)
|
copy(input, tt.input)
|
||||||
rc := nopWriteCloser{bytes.NewBuffer(input)}
|
rc := nopWriteCloser{bytes.NewReader(input)}
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
c := newChild(rc, http.HandlerFunc(func(
|
c := newChild(rc, http.HandlerFunc(func(
|
||||||
w http.ResponseWriter,
|
w http.ResponseWriter,
|
||||||
@ -375,7 +379,7 @@ func TestResponseWriterSniffsContentType(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
input := make([]byte, len(streamFullRequestStdin))
|
input := make([]byte, len(streamFullRequestStdin))
|
||||||
copy(input, streamFullRequestStdin)
|
copy(input, streamFullRequestStdin)
|
||||||
rc := nopWriteCloser{bytes.NewBuffer(input)}
|
rc := nopWriteCloser{bytes.NewReader(input)}
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
var resp *response
|
var resp *response
|
||||||
c := newChild(rc, http.HandlerFunc(func(
|
c := newChild(rc, http.HandlerFunc(func(
|
||||||
|
Loading…
Reference in New Issue
Block a user