libsql-js icon indicating copy to clipboard operation
libsql-js copied to clipboard

Database constructor performs unwanted blocking / erroring operations

Open CodingDoug opened this issue 2 years ago • 0 comments

Running new Database with a configuration that wants to use a remote sqld will cause the program to block on disk or network I/O for some amount of time, potentially for very long amounts of time. It can also cause the constructor to fail. There are two problems with this off the top of my head:

  • It's highly unexpected for a constructor to block in JS, especially for setups that want to eagerly create objects for later use, or expect that their DI never blocks or fails, and always provides an object.
  • It prevents the program from working at all if something is wrong establishing a connection to the server at the time the constructor is called (unless the requirement is that the caller should catch and retry errors with the constructor, which I don't like).

It would be more clean if the constructor only failed on configuration or programming errors (or I suppose whatever might make the underlying better-sqlite3 constructor fail, but it might be reasonable to delay that as well). This would allow the program to work if initially offline or without connection, and make error recovery easier to implement. As an alternative:

  • The request to pull new data could lazily contact the server and yield an error message at that point.
  • The SDK could eagerly contact the server off the main thread so that it's quickly ready for the first sync.

CodingDoug avatar Aug 29 '23 19:08 CodingDoug