Skip to content

Fix/daqstorage unhandled promise rejection#2214

Open
zarch wants to merge 2 commits intofrangoteam:masterfrom
zarch:fix/daqstorage-unhandled-promise-rejection
Open

Fix/daqstorage unhandled promise rejection#2214
zarch wants to merge 2 commits intofrangoteam:masterfrom
zarch:fix/daqstorage-unhandled-promise-rejection

Conversation

@zarch
Copy link

@zarch zarch commented Feb 24, 2026

📌 Description

Problem: The DAQ storage layer emitted recurring UnhandledPromiseRejection errors paired with daqstorage.data-overload warnings on every poll cycle when a device tag was being stored.

Two bugs in server/runtime/storage/sqlite/index.js caused this:

  1. _insertTagValue called reject() with no argument, making the rejection reason undefined instead of the actual SQLite error.
  2. In addDaqValues, the _insertTagValue promises were created before the concurrency guard (_checkDataWorking) was checked. When the guard returned false (overload), those already-running promises had no rejection handler, causing Node.js to raise UnhandledPromiseRejection.

Changes:

  • _insertTagValue now calls reject(err) so the rejection reason is the actual SQLite error.
  • addDaqValues attaches no-op .catch() handlers to orphaned promises when the overload guard fires.
  • Regression tests added in server/test/storage/daqnode.test.js to cover both cases.

🧪 Type of Change

Please mark the relevant option:

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Other

🚫 Build Artifacts Check

Please confirm:

  • I did NOT commit /client/dist
  • I did NOT commit generated Angular build output
  • Only source files are included

🔍 Checklist

  • Code follows project coding standards
  • I tested my changes locally
  • Documentation updated if required
  • Issue opened (for major changes)

📝 Additional Notes

The issue manifests as a pair of log lines repeating on every poll cycle (typically every 1–3 s):

[warn] daqstorage.data-overload! '0'
[error] 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 "undefined".

The regression tests verify both failure modes: running npm test with the fix reverted reproduces the failures, and with the fix applied all tests pass.

Pietro Zambelli added 2 commits February 24, 2026 16:53
- Fix 1: verify _insertTagValue propagates the actual DB error reason
  instead of undefined when a write fails on a closed database
- Fix 2: verify no UnhandledPromiseRejection is raised when
  addDaqValues is called concurrently and the data-overload guard fires
- _insertTagValue now calls reject(err) instead of reject() so the
  rejection reason is the actual SQLite error instead of undefined
- addDaqValues attaches no-op .catch() handlers to orphaned promises
  when the data-overload guard fires, preventing unhandled rejections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant