{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/24445","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/24445/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/24445/comments","events_url":"https://api.github.com/repos/golang/go/issues/24445/events","html_url":"https://github.com/golang/go/issues/24445","id":306380687,"number":24445,"title":"database/sql: segfault in connection pool when the driver frequently fails to connect","user":{"login":"pjm0616","id":484867,"avatar_url":"https://avatars1.githubusercontent.com/u/484867?v=4","gravatar_id":"","url":"https://api.github.com/users/pjm0616","html_url":"https://github.com/pjm0616","followers_url":"https://api.github.com/users/pjm0616/followers","following_url":"https://api.github.com/users/pjm0616/following{/other_user}","gists_url":"https://api.github.com/users/pjm0616/gists{/gist_id}","starred_url":"https://api.github.com/users/pjm0616/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pjm0616/subscriptions","organizations_url":"https://api.github.com/users/pjm0616/orgs","repos_url":"https://api.github.com/users/pjm0616/repos","events_url":"https://api.github.com/users/pjm0616/events{/privacy}","received_events_url":"https://api.github.com/users/pjm0616/received_events","type":"User","site_admin":false},"labels":[{"id":373402289,"url":"https://api.github.com/repos/golang/go/labels/NeedsInvestigation","name":"NeedsInvestigation","color":"ededed","default":false}],"state":"open","locked":false,"assignee":{"login":"kardianos","id":755121,"avatar_url":"https://avatars2.githubusercontent.com/u/755121?v=4","gravatar_id":"","url":"https://api.github.com/users/kardianos","html_url":"https://github.com/kardianos","followers_url":"https://api.github.com/users/kardianos/followers","following_url":"https://api.github.com/users/kardianos/following{/other_user}","gists_url":"https://api.github.com/users/kardianos/gists{/gist_id}","starred_url":"https://api.github.com/users/kardianos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kardianos/subscriptions","organizations_url":"https://api.github.com/users/kardianos/orgs","repos_url":"https://api.github.com/users/kardianos/repos","events_url":"https://api.github.com/users/kardianos/events{/privacy}","received_events_url":"https://api.github.com/users/kardianos/received_events","type":"User","site_admin":false},"assignees":[{"login":"kardianos","id":755121,"avatar_url":"https://avatars2.githubusercontent.com/u/755121?v=4","gravatar_id":"","url":"https://api.github.com/users/kardianos","html_url":"https://github.com/kardianos","followers_url":"https://api.github.com/users/kardianos/followers","following_url":"https://api.github.com/users/kardianos/following{/other_user}","gists_url":"https://api.github.com/users/kardianos/gists{/gist_id}","starred_url":"https://api.github.com/users/kardianos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kardianos/subscriptions","organizations_url":"https://api.github.com/users/kardianos/orgs","repos_url":"https://api.github.com/users/kardianos/repos","events_url":"https://api.github.com/users/kardianos/events{/privacy}","received_events_url":"https://api.github.com/users/kardianos/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/62","html_url":"https://github.com/golang/go/milestone/62","labels_url":"https://api.github.com/repos/golang/go/milestones/62/labels","id":2827591,"number":62,"title":"Go1.11","description":"","creator":{"login":"rsc","id":104030,"avatar_url":"https://avatars1.githubusercontent.com/u/104030?v=4","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":901,"closed_issues":389,"state":"open","created_at":"2017-10-10T13:39:17Z","updated_at":"2018-05-03T11:29:02Z","due_on":"2018-07-31T07:00:00Z","closed_at":null},"comments":7,"created_at":"2018-03-19T09:07:42Z","updated_at":"2018-05-03T15:41:45Z","closed_at":null,"author_association":"NONE","body":"### What version of Go are you using (`go version`)?\r\ngo version go1.10 linux/amd64\r\n\r\n### Does this issue reproduce with the latest release?\r\nyes\r\n\r\n### What operating system and processor architecture are you using (`go env`)?\r\n```\r\nGOARCH=\"amd64\"\r\nGOBIN=\"\"\r\nGOCACHE=\"/home/pjm0616/.cache/go-build\"\r\nGOEXE=\"\"\r\nGOHOSTARCH=\"amd64\"\r\nGOHOSTOS=\"linux\"\r\nGOOS=\"linux\"\r\nGOPATH=\"/home/pjm0616/go\"\r\nGORACE=\"\"\r\nGOROOT=\"/home/pjm0616/local/go\"\r\nGOTMPDIR=\"\"\r\nGOTOOLDIR=\"/home/pjm0616/local/go/pkg/tool/linux_amd64\"\r\nGCCGO=\"gccgo\"\r\nCC=\"gcc\"\r\nCXX=\"g++\"\r\nCGO_ENABLED=\"1\"\r\nCGO_CFLAGS=\"-g -O2\"\r\nCGO_CPPFLAGS=\"\"\r\nCGO_CXXFLAGS=\"-g -O2\"\r\nCGO_FFLAGS=\"-g -O2\"\r\nCGO_LDFLAGS=\"-g -O2\"\r\nPKG_CONFIG=\"pkg-config\"\r\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build045015591=/tmp/go-build -gno-record-gcc-switches\"\r\n```\r\n\r\n### What did you do?\r\nAll line numbers are from go1.10 release (https://github.com/golang/go/blob/bf86aec25972f3a100c3aa58a6abcbcc35bdea49/src/database/sql/sql.go)\r\n```\r\n1062 // Timeout the connection request with the context.\r\n1063 select {\r\n1064 case <-ctx.Done():\r\n1065 \t// Remove the connection request and ensure no value has been sent\r\n1066 \t// on it after removing.\r\n1067 \tdb.mu.Lock()\r\n1068 \tdelete(db.connRequests, reqKey)\r\n1069 \tdb.mu.Unlock()\r\n1070 \tselect {\r\n1071 \tdefault:\r\n1072 \tcase ret, ok := <-req:\r\n1073 \t\tif ok {\r\n1074 \t\t\tdb.putConn(ret.conn, ret.err, false)\r\n1075 \t\t}\r\n1076 \t}\r\n1077 \treturn nil, ctx.Err()\r\n```\r\n\r\nGoroutine 1:\r\nDB.conn() is called. Passes the first context check at line 1021~1026. https://github.com/golang/go/blob/bf86aec25972f3a100c3aa58a6abcbcc35bdea49/src/database/sql/sql.go#L1026\r\n\r\nGoroutine 2:\r\nCancel the context that was passed to DB.conn() in Goroutine 1.\r\n\r\nGoroutine 1:\r\nBlock on db.mu.Lock() on sql.go:1067 https://github.com/golang/go/blob/bf86aec25972f3a100c3aa58a6abcbcc35bdea49/src/database/sql/sql.go#L1067\r\n\r\nGoroutine 3:\r\nDB.openNewConnection() calls db.putConnDBLocked(nil, err).\r\nThe comment for DB.putConnDBLocked() says `If err != nil, the value of dc is ignored`, so this is valid.\r\n\r\nGoroutine 1:\r\nIn sql.go:1072 it receives connRequest{conn: nil, err: err} sent by Goroutine 3.\r\nCalls db.putConn(nil, err).\r\ndb.putConn accesses `dc.inUse` where dc is nil, and panics.\r\n\r\nThe comment for DB.putConn() says `err is optionally the last error that occurred on this connection`,\r\nso there should be a check before calling db.putConn(), but there aren't.\r\n\r\n\r\n\r\n### What did you expect to see?\r\nIt should return an error, ret.err or maybe ctx.Err().\r\n\r\n### What did you see instead?\r\n```\r\npanic: runtime error: invalid memory address or nil pointer dereference\r\n[signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x7f8492]\r\n\r\ngoroutine 304611707 [running]:\r\ndatabase/sql.(*DB).putConn(0xc42265f360, 0x0, 0xd10b60, 0xc422efbd60, 0xc425d19200)\r\n\t/home/pjm0616/local/go/src/database/sql/sql.go:1154 +0x42\r\ndatabase/sql.(*DB).conn(0xc42265f360, 0xd18000, 0xc4269259b0, 0x1, 0x0, 0xc425d19370, 0x5b038a)\r\n\t/home/pjm0616/local/go/src/database/sql/sql.go:1074 +0x9b6\r\ndatabase/sql.(*DB).begin(0xc42265f360, 0xd18000, 0xc4269259b0, 0xc426a38140, 0x1, 0x0, 0x0, 0x0)\r\n\t/home/pjm0616/local/go/src/database/sql/sql.go:1566 +0x4f\r\ndatabase/sql.(*DB).BeginTx(0xc42265f360, 0xd18000, 0xc4269259b0, 0xc426a38140, 0xc425d19498, 0x412169, 0xc42cd9cf30)\r\n\t/home/pjm0616/local/go/src/database/sql/sql.go:1548 +0x8a\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/386339995","html_url":"https://github.com/golang/go/issues/24445#issuecomment-386339995","issue_url":"https://api.github.com/repos/golang/go/issues/24445","id":386339995,"user":{"login":"gopherbot","id":8566911,"avatar_url":"https://avatars1.githubusercontent.com/u/8566911?v=4","gravatar_id":"","url":"https://api.github.com/users/gopherbot","html_url":"https://github.com/gopherbot","followers_url":"https://api.github.com/users/gopherbot/followers","following_url":"https://api.github.com/users/gopherbot/following{/other_user}","gists_url":"https://api.github.com/users/gopherbot/gists{/gist_id}","starred_url":"https://api.github.com/users/gopherbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gopherbot/subscriptions","organizations_url":"https://api.github.com/users/gopherbot/orgs","repos_url":"https://api.github.com/users/gopherbot/repos","events_url":"https://api.github.com/users/gopherbot/events{/privacy}","received_events_url":"https://api.github.com/users/gopherbot/received_events","type":"User","site_admin":false},"created_at":"2018-05-03T15:41:44Z","updated_at":"2018-05-03T15:41:44Z","author_association":"NONE","body":"Backport issue(s) opened: #25235 (for 1.10).\n\nRemember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases."}}
{"actor":{"display_login":"gopherbot"}}