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. |
||
|---|---|---|
| .. | ||
| src | ||
| SignalCoreKitTests.swift | ||