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: DialTimeout w/ "udp4" or "udp6" failing #31058

baloo32 opened this issue Mar 26, 2019 · 4 comments

net: DialTimeout w/ "udp4" or "udp6" failing #31058

baloo32 opened this issue Mar 26, 2019 · 4 comments


Copy link

@baloo32 baloo32 commented Mar 26, 2019

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

$ go version
go version go1.12.1 windows/amd64

Does this issue reproduce with the latest release?

Yes, however, it is not present in v1.11.5 (this is last known good version).

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

go env Output
$ go env
set GOARCH=amd64
set GOBIN=D:\Development\Go\bin
set GOCACHE=C:\Users\XXXX\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Development\work\go
set GOROOT=D:\Development\Go
set GOTOOLDIR=D:\Development\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\XXXX\AppData\Local\Temp\go-build594754674=/tmp/go-build -gno-record-gcc-switches

Windows 10 Professional Version 1809 (OS Build 17763.379) x64
MongoDB version 3.6.11
Golang version 1.12.1

What did you do?

Using the MGO driver ( to connect to a MongoDB instance using the driver's Dial function.

Sample code:

package db

import (

	mgo ""

// MongoDB is a shortcut structure to a MongoDB Database
type MongoDB struct {

// MDB is main DB
var MDB *MongoDB
var mainDBOnce sync.Once

// DialMainDB creates new Mongo session with main DB. Always once.
func DialMainDB(dbHost, dbName string) (err error) {
	if dbName == "" {
		return errors.New("dbHost is not defined")
	if dbName == "" {
		return errors.New("dbName is empty")
	var mgoSession *mgo.Session
	mainDBOnce.Do(func() {
		// Dial Mongo - get session
		mgoSession, err = mgo.Dial(dbHost)
		if err != nil {
		// Check session is alive
		err = mgoSession.Ping()
		if err != nil {

		MDB = &MongoDB{mgoSession.DB(dbName)}
	return err

What did you expect to see?

On versions prior to 1.12.1 the connection to local Mongo is established in less than a second and a correct session and no error is returned from the function. Code is then able to connect and execute against MongoDB.

What did you see instead?

Attempts to connect run for ~10 seconds before timing out. No connection is established, no connection request is seen in the Mongo logs and the session creation fails - program terminates.

The issue has been raised on the driver's Git pages (see globalsign/mgo#338 (comment)) however, initial debugging points to change in Go net package issue instead of mgo driver.

@mikioh mikioh changed the title Unable to establish connection to local MongoDB with Dial net: DialTimeout w/ "udp4" or "udp6" failing Mar 26, 2019
Copy link

@mikioh mikioh commented Mar 26, 2019

Sounds like the DNS stub resolver is broken in Go 1.12 and 1.12.1. Can you please confirm that the issue still happens when GODEBUG=netdns=go on non-Windows platforms. If not, the root cause is probably #30521.

Copy link

@baloo32 baloo32 commented Mar 27, 2019

I don't have access to non-Windows platform - sorry. Will cross post to other repo to see if anyone there can try.

Copy link

@baloo32 baloo32 commented Mar 27, 2019

User on Mac replied with:

when using the GODEBUG=netdns=go on Mac OS X 10.14.18A391 with go1.12.1 darwin/amd64 the issue is resolved.

globalsign/mgo#338 (comment)

Copy link

@mikioh mikioh commented Mar 27, 2019

Thanks for the confirmation. Will merge this issue into #30521 and #31062 is just for tracking the backport to Go 1.12.

@mikioh mikioh closed this Mar 27, 2019
@mikioh mikioh removed the WaitingForInfo label Mar 27, 2019
@mikioh mikioh added this to the Go1.13 milestone Mar 28, 2019
@golang golang locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.