1
0
mirror of https://github.com/golang/go synced 2024-11-17 23:54:51 -07:00

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
This commit is contained in:
Alex Brainman 2013-05-08 16:19:02 +10:00
parent 2f326da27e
commit e1922febbe
2 changed files with 26 additions and 3 deletions

View File

@ -10,14 +10,23 @@ import (
"time" "time"
) )
var testingIssue5349 bool // used during tests
// resolveAndDialChannel is the simple pure-Go implementation of // resolveAndDialChannel is the simple pure-Go implementation of
// resolveAndDial, still used on operating systems where the deadline // resolveAndDial, still used on operating systems where the deadline
// hasn't been pushed down into the pollserver. (Plan 9 and some old // hasn't been pushed down into the pollserver. (Plan 9 and some old
// versions of Windows) // versions of Windows)
func resolveAndDialChannel(net, addr string, localAddr Addr, deadline time.Time) (Conn, error) { func resolveAndDialChannel(net, addr string, localAddr Addr, deadline time.Time) (Conn, error) {
timeout := deadline.Sub(time.Now()) var timeout time.Duration
if timeout < 0 { if !deadline.IsZero() {
timeout = 0 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) t := time.NewTimer(timeout)
defer t.Stop() defer t.Stop()
@ -28,6 +37,9 @@ func resolveAndDialChannel(net, addr string, localAddr Addr, deadline time.Time)
ch := make(chan pair, 1) ch := make(chan pair, 1)
resolvedAddr := make(chan Addr, 1) resolvedAddr := make(chan Addr, 1)
go func() { go func() {
if testingIssue5349 {
time.Sleep(time.Millisecond)
}
ra, err := resolveAddr("dial", net, addr, noDeadline) ra, err := resolveAddr("dial", net, addr, noDeadline)
if err != nil { if err != nil {
ch <- pair{nil, err} ch <- pair{nil, err}

View File

@ -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
}