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

Blocked in function cluster.AcquireSocket #134

Closed
dackon opened this issue Apr 2, 2018 · 7 comments
Closed

Blocked in function cluster.AcquireSocket #134

dackon opened this issue Apr 2, 2018 · 7 comments

Comments

@dackon
Copy link

dackon commented Apr 2, 2018

When mongodb is offline, the client will be blocked in the function cluster.AcquireSocket. Can you add a timeout for this situation? For example, if the client cannot get a live socket in 5s, it will return an error. Thank you.

To reproduce the problem:

  1. Compile the following program.
  2. Run the program
  3. Login to your DB server, and execute the following commands, please replace $CLIENT_IP with your IP:
    sudo iptables -I INPUT -p tcp --dport 27017 -s $CLIENT_IP -j REJECT --reject-with tcp-reset
  4. Check the output of the program, there is no '-------------ERROR is blah blah---------------' or '-------------OK---------------' printed.
  5. Don't forget to delete the iptables commands:
    sudo iptables -D INPUT 1

Codes:

package main

import (
	"log"
	"os"
	"time"

	"github.com/globalsign/mgo"
	"github.com/globalsign/mgo/bson"
)

type barDoc struct {
	bar string `bson:"bar"`
}

func main() {
	var logger = log.New(os.Stderr, "", log.LstdFlags)
	mgo.SetLogger(logger)
	mgo.SetDebug(true)

	url := "user:password@IP:27017/foodb"
	sess, err := mgo.Dial(url)
	if err != nil {
		panic(err)
	}

	for {
		var results []*barDoc

		s := sess.Copy()
		col := sess.DB("foodb").C("bars")
		iter := col.Find(bson.M{}).Iter()

		err = iter.All(&results)

		if err != nil {
			logger.Printf("-------------ERROR is %s---------------", err)
		} else {
			logger.Printf("-------------OK---------------")
		}

		iter.Close()
		s.Close()

		time.Sleep(time.Second)
	}
}
@domodwyer
Copy link

Hi @leopoldfreeman

I think this is probably related to #120 - there's a hotfix pending but it's a public holiday in England, so my colleagues probably won't see it until everyone is back.

I'll close this as I think it should be resolved pretty soon but if it's not, please do reply and I'll reopen.

Dom

@domodwyer domodwyer added the bug label Apr 2, 2018
@domodwyer
Copy link

Hi @leopoldfreeman

Try now, it should be better :)

Dom

@dackon
Copy link
Author

dackon commented Apr 3, 2018

Hi, @domodwyer

I pulled the codes and rebuild the codes, the problem still exists. I checked the hotfix, it's not the same problem.

@dackon
Copy link
Author

dackon commented Apr 3, 2018

My problem is: When mongodb is offline after the client established the connection to the DB, this line will block:

iter := col.Find(bson.M{}).Iter()

@domodwyer
Copy link

Hi @leopoldfreeman

When running your test case, after a while I get:

-------------ERROR is read tcp 127.0.0.1:49602->127.0.0.1:27017: i/o timeout---------------

Perhaps changing the socket timeout or sync timeout might help.

Dom

@dackon
Copy link
Author

dackon commented Apr 3, 2018

I checked it again. You're right. Thank you very much.

@domodwyer domodwyer removed the bug label Apr 3, 2018
@domodwyer
Copy link

Cool, glad it's working for you!

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

2 participants