Closed avinassh closed 1 year ago
@avinassh sorry, missed this, please do send a pull request!
I'm actually working on this change so please don't listen to @penberg :)
Oh, Let me find something else to contribute!
Actually, I won't have time to wrap up this work in the next few days so I think it's best I leave it for you @avinassh :)
I have opened a PR #15 which passes the ctx to http calls. This fixes the first part of the issue.
For the second one, suggest me a safe default timeout to set? How does 120s sound?
Thanks @avinassh. Could you do the same fix for websockets please?
I opened a PR #16 to add changes for websockets and also added timeout for http driver.
Go sql driver now uses ctx for most methods and methods which don't take ctx are deprecated. I believe that should be done here too.
Thanks @avinassh. I think we can close this issue now.
I noticed the library isn't passing the context down to internal methods. This is important since we use ctx for handling deadlines and timeout.
For the user, if they want to cancel the operation if it isn't completed in under 1 second, the code would be:
to fix this, we must pass the ctx to the
callSqld
method and use that in the http calls.The library currently uses the default http package from the stdlib. The calls from this package don't have any timeouts set, so if the server isn't responding, libsql client may get stuck indefinitely. Usually, it is better to set some timeout on http client itself (which will apply to all the calls).
Adding a timeout solves this:
Another alternative is to use hashicorp's cleanhttp package which comes with some sane defaults
I am happy to send a PR to fix these!