urBackend icon indicating copy to clipboard operation
urBackend copied to clipboard

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

Open Kirtan-pc opened this issue 5 months ago • 6 comments

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.

Kirtan-pc avatar Jun 07 '26 09:06 Kirtan-pc

Hi @yash-pouranik ,

I would like to work on this issue under GSSoC 2026.

Could you please assign this issue to me?

Thank you!

Kirtan-pc avatar Jun 07 '26 09:06 Kirtan-pc

Can only assign u to one issue at a time. @Kirtan-pc Choose one from all

yash-pouranik avatar Jun 07 '26 16:06 yash-pouranik

Hey @yash-pouranik, You can assign me any issue as I will be working on it one by one only. You can assign me this issue also.

Thank you.

Kirtan-pc avatar Jun 07 '26 17:06 Kirtan-pc

Hey @yash-pouranik, I have resolved this issue and opened a PR, you can review it any time. You can also assign me other issues that I have created as this issue is resolved. Thank you!

Kirtan-pc avatar Jun 08 '26 09:06 Kirtan-pc

Please mention this issue in that PR. @Kirtan-pc

yash-pouranik avatar Jun 08 '26 13:06 yash-pouranik

@Kirtan-pc , If the issue is completed you should close it

Ayush4958 avatar Jun 28 '26 21:06 Ayush4958