Search code examples
goaerospike

Aerospike randomly returning nil errors when using Query() with Go client


I'm experiencing some strange behavior. I'm trying to set up a small webapp that fetches some data using Aerospike 3.5 Community running on an Ubuntu 12.04 server. I'm using the default aerospike.conf file (using the 'test' namespace) and am following the example of how to query here.

When I attempt to query some records with a filter, the Errors channel randomly is returning a nil error. (This example points to my dev database instance).

To replicate, compile and run the following multiple times, you'll see either data returned or a panic:

package main

import (
    "fmt"

    "github.com/aerospike/aerospike-client-go"
)

func main() {

    c, err := aerospike.NewClient("52.7.157.46", 3000)
    if err != nil {
        panic(err)
    }

    recs := liststuff(c)

    fmt.Printf("got results: %v", recs)
}

func liststuff(client *aerospike.Client) []*aerospike.Record {

    // fetch some records with a filter
    stm := aerospike.NewStatement("test", "products")
    stm.Addfilter(aerospike.NewEqualFilter("visible", 1))
    fmt.Println("querying...")
    recordset, err := client.Query(nil, stm)
    if err != nil {
        panic(err)
    }

    // collect results into a slice
    recs := []*aerospike.Record{}
L:
    for {
        select {
        case rec, chanOpen := <-recordset.Records:
            if !chanOpen {
                break L
            }
            fmt.Println("found record %v", rec)
            recs = append(recs, rec)
        case err := <-recordset.Errors:
            if err != nil {
                panic(err)
            } else {
                panic(fmt.Errorf("error nil when it should exist"))
            }
            return nil
        }
    }

    return recs
}

Solution

  • Just to post an update, both Errors and Records channels are closed automatically when the record stream is over from the server-side, hence the nil value from the Errors channel.

    So this wasn't an error after all. We've updated the thread in our Aerospike user forum post accordingly.