Skip to content

Commit

Permalink
[release-branch.go1.16] net/http: prevent infinite wait during TestMi…
Browse files Browse the repository at this point in the history
…ssingStatusNoPanic

If the client request never makes it to the server, the outstanding
accept is never broken. Change the test to always close the listening
socket when the client request completes.

Updates #45358

Change-Id: I744a91dfa11704e7e528163d7669c394e90456dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/319275
Trust: Heschi Kreinick <heschi@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
(cherry picked from commit c0a7ecf)
Reviewed-on: https://go-review.googlesource.com/c/go/+/320190
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
  • Loading branch information
fraenkel authored and dmitshur committed Jun 2, 2021
1 parent 0410005 commit 1613be8
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/net/http/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5314,7 +5314,6 @@ func TestMissingStatusNoPanic(t *testing.T) {

ln := newLocalListener(t)
addr := ln.Addr().String()
shutdown := make(chan bool, 1)
done := make(chan bool)
fullAddrURL := fmt.Sprintf("http://%s", addr)
raw := "HTTP/1.1 400\r\n" +
Expand All @@ -5326,10 +5325,7 @@ func TestMissingStatusNoPanic(t *testing.T) {
"Aloha Olaa"

go func() {
defer func() {
ln.Close()
close(done)
}()
defer close(done)

conn, _ := ln.Accept()
if conn != nil {
Expand Down Expand Up @@ -5360,7 +5356,7 @@ func TestMissingStatusNoPanic(t *testing.T) {
t.Errorf("got=%v want=%q", err, want)
}

close(shutdown)
ln.Close()
<-done
}

Expand Down

0 comments on commit 1613be8

Please sign in to comment.