aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2013-05-08 15:58:43 -0700
committerAndrew Gerrand <adg@golang.org>2013-05-08 15:58:43 -0700
commit99aa2da7ea1f82eb8385835e5e7bf293c8da4fb5 (patch)
tree218fb2235cf2a862a329c31110784cadeac45144
parent0f1a18b773c57d8d8a2897ece9724042c7ad5581 (diff)
downloadgo-99aa2da7ea1f82eb8385835e5e7bf293c8da4fb5.tar.gz
go-99aa2da7ea1f82eb8385835e5e7bf293c8da4fb5.zip
[release-branch.go1.1] net: fix dial race on plan9 and windows
««« CL 9159043 / f1ddc3ce3dfe net: fix dial race on plan9 and windows Fixes #5349. R=golang-dev, lucio.dere, dsymonds, bradfitz, iant, adg, dave, r CC=golang-dev https://golang.org/cl/9159043 »»» R=golang-dev CC=golang-dev https://golang.org/cl/9315043
-rw-r--r--src/pkg/net/dial_gen.go18
-rw-r--r--src/pkg/net/dial_gen_test.go11
2 files changed, 26 insertions, 3 deletions
diff --git a/src/pkg/net/dial_gen.go b/src/pkg/net/dial_gen.go
index 0a3277de46..19f8681682 100644
--- a/src/pkg/net/dial_gen.go
+++ b/src/pkg/net/dial_gen.go
@@ -10,14 +10,23 @@ import (
"time"
)
+var testingIssue5349 bool // used during tests
+
// resolveAndDialChannel is the simple pure-Go implementation of
// resolveAndDial, still used on operating systems where the deadline
// hasn't been pushed down into the pollserver. (Plan 9 and some old
// versions of Windows)
func resolveAndDialChannel(net, addr string, localAddr Addr, deadline time.Time) (Conn, error) {
- timeout := deadline.Sub(time.Now())
- if timeout < 0 {
- timeout = 0
+ var timeout time.Duration
+ if !deadline.IsZero() {
+ timeout = deadline.Sub(time.Now())
+ }
+ if timeout <= 0 {
+ ra, err := resolveAddr("dial", net, addr, noDeadline)
+ if err != nil {
+ return nil, err
+ }
+ return dial(net, addr, localAddr, ra, noDeadline)
}
t := time.NewTimer(timeout)
defer t.Stop()
@@ -28,6 +37,9 @@ func resolveAndDialChannel(net, addr string, localAddr Addr, deadline time.Time)
ch := make(chan pair, 1)
resolvedAddr := make(chan Addr, 1)
go func() {
+ if testingIssue5349 {
+ time.Sleep(time.Millisecond)
+ }
ra, err := resolveAddr("dial", net, addr, noDeadline)
if err != nil {
ch <- pair{nil, err}
diff --git a/src/pkg/net/dial_gen_test.go b/src/pkg/net/dial_gen_test.go
new file mode 100644
index 0000000000..c857acd06d
--- /dev/null
+++ b/src/pkg/net/dial_gen_test.go
@@ -0,0 +1,11 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build windows plan9
+
+package net
+
+func init() {
+ testingIssue5349 = true
+}