influxdata / influxdb1-client

The old clientv2 for InfluxDB 1.x
MIT License
190 stars 112 forks source link

Client is not thread safe #53

Open asettouf opened 3 years ago

asettouf commented 3 years ago

Hi,

after some thorough testing with goroutines, I do not understand how the documentation can claim:

// client is safe for concurrent use as the fields are all read-only
// once the client is instantiated.

Indeed, trying this snippet of code in a for loop works properly:

q := client.NewQuery(query_string, "mydb", "s")
response, err := c.Query(q)

However trying the same in a for loop starting goroutines, most of my functions error out with: 2021/04/29 15:05:24 Error querying influx unable to decode json: received status code 200 err: unexpected EOF

Now with goroutines, the same snippet works with a sync.Mutex:

l.Lock()
q := client.NewQuery(query_string, "schoonschip", "s")
response, err := c.Query(q)
l.Unlock()

What am I missing here?