Skip to content

nodejs: "Timeout while waiting on backend" when createSQLiteThread() #361

@jbeuckm

Description

@jbeuckm

I can't get the worker going in node v22.14.0

I had to hack the package.json for this package to include an export for "require" under line 11.

Here is what I'm trying to add to my service:

import { Worker } from 'worker_threads'
globalThis.Worker = Worker as any

const { createHttpBackend, createSQLiteThread } = require('sqlite-wasm-http')

const httpBackendGlobale = createHttpBackend({
  maxPageSize: 4096, // this is the current default SQLite page size
  timeout: 5000, // 5s
  cacheSize: 4096, // 4 MB
})
console.log('httpBackendGlobale', httpBackendGlobale)

createSQLiteThread({ http: httpBackendGlobale })
  .then(db => console.log('ready', db))
  .catch(e => console.log(e))

After my 5sec (or 60+ sec) timeout expires, I crash like this:

node:internal/process/promises:392
      new UnhandledPromiseRejection(reason);
      ^

UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Timeout while waiting on backend".
    at throwUnhandledRejectionsMode (node:internal/process/promises:392:7)
    at processPromiseRejections (node:internal/process/promises:475:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:106:32) {
  code: 'ERR_UNHANDLED_REJECTION'
}

MORE:

I now realize that the readme says to use web-worker so I'm trying to import that but have a similar module resolution problem:

SyntaxError: Cannot use import statement outside a module
    at new Script (node:vm:117:7)
    at createScript (node:vm:269:10)
    at Object.runInThisContext (node:vm:317:10)
    at importScripts (/Users/jbeuckman/Documents/marketplace-app/node_modules/web-worker/dist/node/index.cjs:121:32)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions