Skip to content

fix: an uncaught error in a plugin no longer stops the api or the worker - #49

Merged
BatLeDev merged 4 commits into
masterfrom
fix-plugin-uncaught-errors
Nov 20, 2026
Merged

BatLeDev merged 4 commits into
masterfrom
fix-plugin-uncaught-errors

Conversation

@BatLeDev

@BatLeDev BatLeDev commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Plugin methods now run in an async context (AsyncLocalStorage, the mechanism behind withLogContext) that names the plugin call, in the api (getPlugin) and in the worker. A process-level handler classifies uncaught exceptions and unhandled rejections:

  • raised in a plugin call: logged as plugin-uncaught-error (plugin, pluginMethod), the pending call rejects with that error and the process keeps running;
  • raised after its call settled (a connection the plugin reuses across calls): every pending call of the same plugin rejects, so a worker task cannot hang forever;
  • anything else, or 10 uncaught errors of the same plugin in 10 minutes: logged (uncaught-error, plugin-uncaught-errors-limit), then exit 1.

Task log callbacks given to plugins run outside of the plugin context, so an error on a host resource they open (mongo, ws) still stops the process. Plugin calls made by the api (prepare, list) fail with a 504 after 60 s (plugin-call-timeout warning); prepare lets a 5xx through instead of turning it into a 400.

Why: an ECONNRESET emitted by the ssh2 client of catalog-sftp after the connection, with no 'error' listener, crashed the catalogs api on every attempt in a user's scenario. The plugin is fixed in catalog-sftp 0.5.2. This makes sure another plugin bug of the same kind fails its own call instead of taking down the service.

Heads-up:

  • The process keeps running after an uncaught plugin error. Work abandoned by a failed or timed-out call (open sockets, tmpDir files) is not cleaned up until the next restart; the error limit bounds that.
  • Attribution follows the context a resource was created in. A resource a plugin creates at module load is not attributed and still stops the process, as before.
  • The worker has no plugin call timeout: an import can legitimately take hours.
  • A non-plugin crash is now a structured pino line with exit code 1, instead of Node's stderr dump with exit code 7.

Plugin methods run in an async context that names the plugin. The
process-level handler logs an uncaught exception or unhandled rejection
raised in that context (plugin-uncaught-error) and keeps the process
running; any other one is logged (uncaught-error) and still exits.
@github-actions github-actions Bot added the fix label Nov 20, 2026
…lugin calls

The uncaught error handler now rejects the pending plugin call with the
error it raised, so an api request answers and a worker task releases
its slot instead of waiting forever. Plugin calls made by the api
(prepare, list) also fail with a 504 after 60 s.
- an uncaught error raised after its plugin call settled (a connection
  reused across calls) fails the pending calls of the same plugin, so a
  worker task cannot hang forever
- task log callbacks run outside of the plugin context: an error on a
  host resource they open still stops the process
- more than 20 uncaught plugin errors in 10 minutes stop the process
- a plugin call timeout is logged as a warning, the api timeout is 45 s
- prepare lets a 5xx error through instead of turning it into a 400
@github-actions github-actions Bot added fix and removed fix labels Nov 20, 2026
…0 s api timeout

The ingresses in front of catalogs time out after 600 s, a 60 s plugin
call timeout answers well before them.
@github-actions github-actions Bot added fix and removed fix labels Nov 20, 2026
@BatLeDev
BatLeDev marked this pull request as ready for review November 20, 2026 16:03
@BatLeDev
BatLeDev merged commit 9ff4825 into master Nov 20, 2026
5 checks passed
@BatLeDev
BatLeDev deleted the fix-plugin-uncaught-errors branch November 20, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant