Skip to content

[Bug] public-api: Log.create in api_usage.js is fire-and-forget without error isolation — unhandled rejection can crash the logger #283

@Kirtan-pc

Description

@Kirtan-pc

Description

In api_usage.js Log.create(...) is called without await and without a .catch() handler. If the MongoDB write throws (e.g., validation error, connection drop), Node.js emits an UnhandledPromiseRejection. In Node 18+, this terminates the process. A secondary issue: ApiAnalytics.create(...) inside setImmediate similarly has no per-call rejection guard — only a broad console.error.

Steps to Reproduce

  1. Start public-api with NODE_ENV=development.
  2. Drop or saturate the MongoDB connection while making any API call.
  3. Observe that the logger's fire-and-forget Log.create() emits an UnhandledPromiseRejection.
  4. On Node 18+, the process exits unexpectedly.

Expected Behaviour

Logging failures should be silently swallowed (or re-routed to a fallback) without crashing or interrupting the request/response cycle.

Actual Behaviour

Log.create({...}) is called without .catch(). Any thrown error propagates as an unhandled rejection and can terminate the Node.js process.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions