surrealdb.js icon indicating copy to clipboard operation
surrealdb.js copied to clipboard

Bug: db is not reconnecting

Open finalclass opened this issue 1 year ago • 3 comments

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/[email protected]/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

[email protected]

Is there an existing issue for this?

  • [X] I have searched the existing issues

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

finalclass avatar Dec 14 '23 20:12 finalclass

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.

dodanex avatar Jan 27 '24 16:01 dodanex

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.

oliver-oloughlin avatar Mar 28 '24 23:03 oliver-oloughlin

Same problem occurs with the latest beta version. Also, if I subscribe for the ConnectionStatus.Error or ConnectionStatus.Disconnected event, non of them gets triggered if SurrealDB is shut down. The node app gets killed because of the exception:

node:internal/deps/undici/undici:13178
      Error.captureStackTrace(err);
            ^

TypeError: fetch failed
    at node:internal/deps/undici/undici:13178:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async HttpEngine.rpc (file:///usr/src/app/apps/web/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected][email protected]_/node_modules/surrealdb/dist/index.mjs:1:33547)
    at async Surreal.signin (file:///usr/src/app/apps/web/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected][email protected]_/node_modules/surrealdb/dist/index.mjs:1:40207)
    at async Timeout.eval [as _onTimeout] (/usr/src/app/apps/web/src/lib/utils/surrealdb/db.server.ts:28:7) {
  [cause]: Error: getaddrinfo ENOTFOUND surrealdb
      at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26)
      at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'surrealdb'
  }
}

Node.js v20.16.0
 ELIFECYCLE  Command failed with exit code 1.


akkie avatar Aug 19 '24 09:08 akkie