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

mgo: FindAndModify create too many sockets #397

Open
andrewrong opened this issue Mar 3, 2021 · 0 comments
Open

mgo: FindAndModify create too many sockets #397

andrewrong opened this issue Mar 3, 2021 · 0 comments

Comments

@andrewrong
Copy link

We use the issue tracker to track bugs with mgo - if you have a usage question,
it's best to try Stack Overflow :)

Replace this text with your description, and please answer the questions below
before submitting your issue to help us out. Thanks!


What version of MongoDB are you using (mongod --version)?

3.4

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

go version go1.14.7 

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

GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.7/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/h3/k95txtxn3wq3nvxx5xxcnj280000gn/T/go-build203709446=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. init 100 mgo.session (mgo session is not use),
  2. Multiple(for example 100) goroutine run command FindAndModify use session that the step created
  3. you find that mgo create many socket connects mongos

I look the FindAndModify's source code

globalsign/mgo/session.go::Apply()::5032

		session = session.Clone()
		defer session.Close()
		session.SetMode(Strong, false)

If the concurrency using FindAndModify is high enough, then many connections will be created;
I think it can be modified like this:

	if session.Mode() != Strong {
		session = session.Clone()
		defer session.Close()
		session.SetMode(Strong, false)
	}

Can you reproduce the issue on the latest development branch?

yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant