SignalCoreKit/SignalCoreKitTests
Michelle Linington a2f6bd08cc Long promise chains can overflow thread's stack
The issue:
`asyncIfNecessary` will always synchronously execute the provided
closure if the target queue and the current queue are the same.

Since promises chains can become extremely long, especially with any
sort of retry behavior, it's possible to exhaust the stack this way. The
overhead for each synchronous promise is ~2.5k of stack size per step.

The fix:
If we want to continue to use `asyncIfNecessary`, we should consider it
"necessary" to async if we're approaching the stack boundary of the
current thread.

This is a bit of a hack, but it seems to work in testing. It's also
reasonably safe. If this does introduce a bug, it'll just be that we're
too aggressive about asyncing. But asyncs are always correct,
synchronous execution of the promise closure is just a perf
optimization.
2021-09-17 23:42:17 -07:00
..
src Long promise chains can overflow thread's stack 2021-09-17 23:42:17 -07:00
SignalCoreKitTests.swift Initial code drop. 2018-09-21 12:47:57 -04:00