Skip to content

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

Open
zensh wants to merge 2 commits into
go-mgo:v2from
alibaba-archive:issue/fix-socket-error
Open

try to fix socket i/o error for session#506
zensh wants to merge 2 commits into
go-mgo:v2from
alibaba-archive:issue/fix-socket-error

Conversation

@zensh

@zensh zensh commented Oct 17, 2017

Copy link
Copy Markdown

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

zensh commented Oct 17, 2017

Copy link
Copy Markdown
Author

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

@zensh

zensh commented Oct 18, 2017

Copy link
Copy Markdown
Author

After this PR,we can use:

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

instead of

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

@zensh

zensh commented Oct 27, 2017

Copy link
Copy Markdown
Author

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

zensh commented Nov 14, 2017

Copy link
Copy Markdown
Author

@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

Development

Successfully merging this pull request may close these issues.

1 participant