surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
293 stars 48 forks source link

Bug: `beta.8` might've introduced some weird authentication timeout crash bug #287

Open AlbertMarashi opened 3 months ago

AlbertMarashi commented 3 months ago

Describe the bug

I think https://github.com/surrealdb/surrealdb.js/commit/c063200b70e02d7e6fd3e11b1af2d96ba4e0eabe may have introduced some kind of timeout bug or authentication bug

Unhandled Rejection: VersionRetrievalFailure: Failed to retrieve remote version. If the server is behind a proxy, make sure it's configured correctly.
at file:///var/task/node_modules/surrealdb.js/esm/library/versionCheck.js:34:19
at runNextTicks (node:internal/process/task_queues:60:5)
at process.processTimers (node:internal/timers:511:9)
at async retrieveRemoteVersion (file:///var/task/node_modules/surrealdb.js/esm/library/versionCheck.js:28:25)
at async Surreal.connect (file:///var/task/node_modules/surrealdb.js/esm/surreal.js:78:29)
at async get_surreal_db_client (file:///var/task/.svelte-kit/output/server/chunks/hooks.server.js:159:3)
Node.js process exited with exit status: 128. The logs above can help with debugging the issue.

This ends up crashing the app because it's not handling the error.

Steps to reproduce

I tested with local db version 5.3 and 1.4.2 in production, both were having these issues. Which makes me think it's SDK issue (I was previously running 0.11 and migrating to v1.0

However, downgrading to beta-7 appear to not have this issue

Expected behaviour

App should not crash, not exactly sure what is happening here

SurrealDB version

1.5.3 on production 1.4.2

SurrealDB.js version

1.0.0-beta.9

Contact Details

albert@siteforge.io

Is there an existing issue for this?

Code of Conduct

AlbertMarashi commented 3 months ago

I'm not sure exactly what's happening here, but I think it's some time out issue that happens after a certain amount of minutes, not sure exactly how long

AlbertMarashi commented 3 months ago

Both beta.9 and beta.8 have this issue. beta.7 does not and likely has something to do with https://github.com/surrealdb/surrealdb.js/commit/c063200b70e02d7e6fd3e11b1af2d96ba4e0eabe

AlbertMarashi commented 3 months ago

This appears to be an issue with the SDK doing pings on HTTP(s) protocol, when pings should only be used with the ws(s) protocol.

Temporary workaround: use websockets protocol to connect to server instead of HTTP(s)

5hanth commented 3 months ago

this happens with websockets as well.

AlbertMarashi commented 3 months ago

this happens with websockets as well.

Did you try beta.7 to fix your issue?

ioannist commented 2 months ago

This issue was present in beta.12 too. The authenticated session expires and you have to setup a DB connection afresh. This means one of two things

HttpConnectionError: There was a problem with authentication
    at HttpEngine.rpc (file:///var/task/node_modules/surrealdb.js/dist/index.mjs:1:33564)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Surreal.query_raw (file:///var/task/node_modules/surrealdb.js/dist/index.mjs:1:41722)
    at async Surreal.query (file:///var/task/node_modules/surrealdb.js/dist/index.mjs:1:41427)
reinhard-sanz commented 1 month ago

Have got the same problem as @ioannist :/ It's really annoying because it used to work once and now if the session expires your surrealdb client is basically bricked... 😅

AlbertMarashi commented 1 month ago

@reinhard-sanz have you tried updating your surreal to a later version like beta.20 and using websocket instead of http?

-https://foo.com:8000
+wss://foo.com:8000
or
-http://foo.com:8000
+ws://foo.com:8000
reinhard-sanz commented 1 month ago

@AlbertMarashi ok after switching to websocket it seems to work now :) Thx!