Closed bufanyun closed 2 years ago
If you re-run the service after the timeout, it will be normal, and checking the status of influxdb is also running
@bufanyun, if I understood correctly, by continuous data query you mean a loop in which you are repeatedly sending a query request to a server, right? If yes, the query can take a long time.
What you can do: 1) Increase timeout. Default timeout is 20s. You can increase it via options:
opts := influxdb2.DefaultOptions().SetHTTPRequestTimeout(40)
client := influxdb2.NewClientWithOptions("htp://localhost:8086", authToken, opts)
2) Don't panic on errors. Calling panic
is part of the examples, but it is not recommended in production code. Good practice is retrying a request on an error. You can also add simple backoff loop:
for _, tm := range []time.Duration{2, 5, 10} {
result, err := queryAPI.Query(context.Background(), query)
if err == nil {
// process result
break
} else {
// wait a bit
<-time.After(tm*time.Second)
}
}
Well said, thank you so much!
In the continuous data query, there will often be a timeout, and then the service will exit directly. Do you have any good suggestions, thank you!