rethinkdb“打开的文件太多”错误

I used the golang driver provided by https://github.com/dancannon/gorethink. It is my understanding that i never close connection and reconnect. I can't close the connection because i don't know how to get the connection. What i know how is to get the session, and starting to think i don't know the right way to get the session.

So my question is:

  1. How to fix the error?
  2. How to close connection and reconnect?

EDIT:

@OneOfOne Not some, basically all of the related code:

// How i define session:
session, e := r.Connect(r.ConnectOpts{
    Address:  "localhost:28015",
    Database: "database",
    MaxActive: 0,
    MaxIdle: 0,
    // IdleTimeout: time.Minute,
})
//
// Inserting
inserts := map[string]interface{}{"something": something, "something1": something1, "something2": something2}
r.Db("database").Table("table").Insert(inserts).RunWrite(session)
//
// Updating
r.Db("database").Table("table").Filter(map[string]interface{}{"parameter": parameter}).Update(map[string]interface{}{"something" : somethingMore}).RunWrite(session)
//
// Get some row
row, e := r.Db("database").Table("table").Filter(map[string]interface{}{"parameter": parameter}).RunRow(session)
if e!= nil {
    //error
}

@neumino: This is what comes out when i hit ulimit -a

└─ $ ▶ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 30419
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 30419
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

I don't know whether this is too low or too high.

@VonC : That's one of the things that i don't get, I can't see how connection is inside the pool:

//http://godoc.org/github.com/dancannon/gorethink#Pool
type Pool struct {
    Session *Session

    // Maximum number of idle connections in the pool.
    MaxIdle int

    // Maximum number of connections allocated by the pool at a given time.
    // When zero, there is no limit on the number of connections in the pool.
    MaxActive int

    // Close connections after remaining idle for this duration. If the value
    // is zero, then idle connections are not closed. Applications should set
    // the timeout to a value less than the server's timeout.
    IdleTimeout time.Duration
    // contains filtered or unexported fields
}

Or did I just misunderstand what a pool is or what a connection is (or even what a session is)?

You can first look at your current limit, maybe it's excessively low? Run ulimit -a to see your settings

If you need to increase the number of open files, you can run ulimit -n <number of open files>.

I don't see any obvious problem in your defaultStore.go file. The cursor are closed, and the connection should be released. I gave a quick look at your code, and it doesn't seem that you create unnecessary sessions/pool, so I'm not sure where is the problem (or maybe I missed something?).