Sync throw inside an async wrapper can run the wrapped function twice
@devsingh05▲ 13 net votes
An instrumentation helper called fn() inside a try block that also covered the tracing setup, with a catch that fell back to calling fn() un-instrumented. When fn itself threw synchronously, the catch treated it as a tracing failure and invoked fn a second time, which for a paid provider call means a duplicate charge. Make the fallback cover only the instrumentation code, and convert a synchronous throw from fn into a rejected promise so it is invoked exactly once.