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

Issue with reusing connection in another go procedure.. #234

Open
dyatlov opened this issue Sep 7, 2015 · 1 comment
Open

Issue with reusing connection in another go procedure.. #234

dyatlov opened this issue Sep 7, 2015 · 1 comment

Comments

@dyatlov
Copy link

dyatlov commented Sep 7, 2015

Getting this error when trying to reuse connection from another go procedure:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x12c8bf]

goroutine 50 [running]:
github.com/mattbaird/elastigo/lib.(*Conn).NewRequest(0x0, 0x3dacb0, 0x3, 0xc8201c9050, 0x25, 0x0, 0x0, 0xc820055180, 0x0, 0x0)
    /Users/dyatlov/go/src/github.com/mattbaird/elastigo/lib/connection.go:138 +0x9ef
github.com/mattbaird/elastigo/lib.(*Conn).DoCommand(0x0, 0x3dae50, 0x3, 0xc82015b170, 0x25, 0x0, 0x2c0840, 0xc8200fe5a0, 0x0, 0x0, ...)
    /Users/dyatlov/go/src/github.com/mattbaird/elastigo/lib/baserequest.go:33 +0x18b
github.com/mattbaird/elastigo/lib.(*Conn).IndexWithParameters(0x0, 0x7fff5fbffa70, 0x8, 0x3dd740, 0x7, 0xc8202265c0, 0x12, 0x0, 0x0, 0x0, ...)
    /Users/dyatlov/go/src/github.com/mattbaird/elastigo/lib/coreindex.go:56 +0x28a
github.com/mattbaird/elastigo/lib.(*Conn).Index(0x0, 0x7fff5fbffa70, 0x8, 0x3dd740, 0x7, 0xc8202265c0, 0x12, 0x0, 0x2c0840, 0xc8200fe5a0, ...)
    /Users/dyatlov/go/src/github.com/mattbaird/elastigo/lib/coreindex.go:37 +0x147

But if I create another connection in go procedure itself (in the same way as I do in main() ) then all goes fine.

Some pieces of my code:

// ESHost Elasticsearch host
var ESHost = flag.String("eshost", "localhost", "Elasticsearch Server Host Address")

// ESPort Elasticsearch port
var ESPort = flag.String("esport", "9200", "Elasticsearch Server Port Address")

// ESIndex Elasticsearch index name
var ESIndex = flag.String("esindex", "websites", "Elasticsearch Index Name")

// ESCon Elasticsearch connection
var ESCon *elastigo.Conn

// WG for waiting for all threads to complete
var WG sync.WaitGroup

func main() {
    flag.Parse()

    ESCon := elastigo.NewConn()
    ESCon.Domain = *ESHost
    ESCon.Port = *ESPort

    _, err := ESCon.Count(*ESIndex, "product", nil, nil) // it all is fine here

    if err != nil {
        checkErr(err)
    }

       // then I create a pull of background workers..
       // and try to reuse ESCon in there ( ESCon.Index(..) ), but it fails with the error above
}
@brianfoshee
Copy link

elastigo.Conn is not thread safe, so you'll have to create a new instance in each worker.

See this open PR #165

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