tursodatabase / libsql-client-go

Go client API for libSQL
MIT License
166 stars 23 forks source link

Driver didn't handle hrana stream expiration, will error every ~300s of idle time #60

Closed intagaming closed 11 months ago

intagaming commented 1 year ago

The Go driver will error "Received an invalid baton" when the db connection idles for about > 300s. Related code here: https://github.com/libsql/sqld/blob/919bee19214669bbaf5268ecb81b0b3961b699fe/sqld/src/hrana/http/stream.rs#L317C52-L317C52

In the demo repo below I set the interval between queries = 500s.

https://github.com/intagaming/sqld-error

Clone the repo and run it with DATABASE_URL=http://127.0.0.1:8989 go run .. You can start a sqld instance with docker run -p 8989:8080 -d ghcr.io/libsql/sqld:latest.

image

honzasp commented 11 months ago

When a client connects to sqld over HTTP (using Hrana over HTTP), the SQL connection (Hrana stream) will be closed after 10 seconds of inactivity; however, the server still remembers the stream for 300 seconds, so that it can provide a more useful error message. If the Go client reports an error after 300 seconds, perhaps it (incorrectly) relies on the STREAM_EXPIRED error?

honzasp commented 11 months ago

It does indeed: https://github.com/libsql/libsql-client-go/blob/eeb7070ee77fb0adfd5b41420eff72cd0f282561/libsql/internal/http/hranaV2/hranaV2.go#L241

honzasp commented 11 months ago

The client should use Hrana over WebSocket, it would not have this issue.