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

try to fix socket i/o error for session #506

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from

Conversation

zensh
Copy link

@zensh zensh commented Oct 17, 2017

If socket was killed, it should be removed in session so that new socket can be setup for session.

@zensh zensh changed the title try to fix socket error for session try to fix socket error (i/o timeout) for session Oct 17, 2017
@zensh zensh changed the title try to fix socket error (i/o timeout) for session try to fix socket i/o error for session Oct 17, 2017
@zensh
Copy link
Author

zensh commented Oct 17, 2017

@niemeyer https://travis-ci.org/go-mgo/mgo/jobs/289072737 this job failed, it should be restart~

@zensh
Copy link
Author

zensh commented Oct 18, 2017

After this PR,we can use:

s := session.Clone()
defer s.Close()

instead of

s := session.Copy()
defer s.Close()

@zensh
Copy link
Author

zensh commented Oct 27, 2017

We can try the issue with code:

func main() {
	session, err := mgo.DialWithInfo(someRemoteDailInfo)
	if err != nil {
		panic(err)
	}

	for {
		fmt.Println("Ping:", session.Ping())
		time.Sleep(time.Second)
	}
}

Run it, then close the wifi, and then open the wifi, some result like this:

Ping: <nil>
Ping: <nil>
Ping: <nil>
Ping: <nil>
Ping: <nil>
Ping: <nil>
Ping: <nil>
Ping: read tcp 192.168.0.72:58883->192.168.0.21:27017: i/o timeout
Ping: no reachable servers
Ping: <nil>
Ping: <nil>
Ping: <nil>

It means that the session will reconnect automatic.

@zensh
Copy link
Author

zensh commented Nov 14, 2017

@niemeyer Could you review this PR? We have used the fork version in our productions

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