surrealdb / surrealdb.js

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

Bug: db is not reconnecting #203

Open finalclass opened 7 months ago

finalclass commented 7 months ago

Describe the bug

When surrealdb dies the library does not try to reconnect and it's not throwing (catchable) error.

Steps to reproduce

  1. Start surreal
  2. Create new Surreal(), connect, signin, use...
  3. stop surreal
  4. start it again
  5. try running some query using the new Surreal() instance.

This is the error:

error: Uncaught (in worker "") (in promise) InvalidStateError: readyState not OPEN
        this.ws?.send(JSON.stringify({ id, method, params }));
                 ^
    at WebSocket.send (ext:deno_websocket/01_websocket.js:327:13)
    at SurrealSocket.send (https://deno.land/x/surrealdb@v0.11.0/src/library/SurrealSocket.ts:133:12)
    at eventLoopTick (ext:core/01_core.js:197:13)

Expected behaviour

The library either:

  1. throws an error which can be caught
  2. executuse "onError" hook
  3. tries to reconnect

SurrealDB version

1.0.0+20230913.54aedcd for linux on x86_64

SurrealDB.js version

0.11.0

Contact Details

s@finalclass.net

Is there an existing issue for this?

Code of Conduct

dodanex commented 5 months ago

Bug confirmed on SurrealDB v1.1.1 & SurrealDB.js v0.11.0 While having a Nuxt.js app running and connected to the database, everything works fine until you crash or close the database. After you open the DB again the Nuxt app is not able to connect so you need to restart the Nuxt server.

oliver-oloughlin commented 3 months ago

Reproduced using Deno 1.40.0 + Surrealdb v1.2.0 + surrealdb.js v0.11.0. The part about uncatchable errors is a major issue for me, and makes the driver unusable in my use case. It seems WebSockets in Deno are unstable and tend to lose connection at random. This bug prevents the connection from being reestablished, and crashes my program as I am unable to catch the errors and reconnect manually.