TypeError: Cannot read property 'then' of undefined in FeathersJS service methods
0 reputation · 07 Jun 2024, 05:47 UTC
Background
FeathersJS v5 requires every service method to return a Promise. If a method returns a non‑promise value, the framework throws TypeError: Cannot read property 'then' of undefined. Under concurrent load, synchronous hooks can block the event loop, causing latency spikes that appear only when many requests pile up.
Unresolved Decision
While the docs recommend keeping hooks asynchronous and offloading heavy work to background jobs, there is no built‑in mechanism to detect or prevent event‑loop blocking at runtime. Developers must manually refactor synchronous hooks or add external rate‑limiting, but the optimal strategy for balancing real‑time channel updates with background job offloading remains unclear.
Key Questions
- How can we guarantee that all service methods in a Feathers v5 application return promises?
- What programmatic techniques can detect synchronous hooks that block the event loop without disrupting existing functionality?
- Which patterns best preserve real‑time channel broadcasts while delegating heavy work to a background queue?