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

how to ensure the sockets in unusedSockets available #369

Open
NeoyeElf opened this issue Jul 12, 2019 · 0 comments
Open

how to ensure the sockets in unusedSockets available #369

NeoyeElf opened this issue Jul 12, 2019 · 0 comments

Comments

@NeoyeElf
Copy link

NeoyeElf commented Jul 12, 2019

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

3.4

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

1.11

What did you do?

my program uses the mgo to connect to a mongo shard cluster. When the concurrent requests increase rapidly, some of my mongo query would return err like "insert err:write results unavailable from ${ip} :: caused by :: Location11002: socket exception [CONNECT_ERROR]".

I think the socket occurs some network connection error, so I use the following code to get a new session(I.e. socket)

session.Close()
globalSession.Copy()

The problem seems to be solved.

recently, I have dig into some of the source code and have some questions for the following code:

// Release decrements a socket reference. The socket will be
// recycled once its released as many times as it's been acquired.
func (socket *mongoSocket) Release() {
	socket.Lock()
	if socket.references == 0 {
		panic("socket.Release() with references == 0")
	}
	socket.references--
	stats.socketRefs(-1)
	if socket.references == 0 {
		stats.socketsInUse(-1)
		server := socket.server
		closeAfterIdle := socket.closeAfterIdle
		socket.Unlock()
		socket.LogoutAll()
		if closeAfterIdle {
			socket.Close()
		} else if server != nil {
			// If the socket is dead server is nil.
			server.RecycleSocket(socket)
		}
	} else {
		socket.Unlock()
	}
} 

Here is my question:
if a socket that has some network connection error(like I said above) is put back to the unusedSockets slice by calling the session.Close(), which calls socket.Release(), will I encounter the error again when I use the session acquire the socket from unusedSockets? Have not seen any code to ensure the socket available(or I just missed)

Thks!

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