Menu

1 / 3

Actor reentrancy bugs in real apps: 5 patterns and how to fix them

DEV Community: ios·Dheerendra Chaturvedi·2 days ago
#LibsOAzd
#devtoios#devto#dev#await#task
Long article (2076 words) — no AI summary yet.
Reading 0:00
15s threshold

A quick follow-up to Swift 6 actors and concurrency: how they work, reentrancy pitfalls, and what's new in 6.2 . That post covered the mechanics; this one is the field guide. One-line recap: Swift actors are reentrant — whenever an actor method hits an await , the actor is free to run other queued calls before that method resumes, so an actor method is not atomic across its suspension points.

That single fact is behind a whole class of bugs that sail through code review and unit tests and then surface in production. They pass review because the method reads correctly top to bottom when you trace one call. They pass tests because most tests fire one call at a time, and the bug needs two callers racing at the exact same await . Under real load — a user double-tapping, two screens observing the same model, a retry colliding with the original — that race stops being rare.

Below are five patterns I keep seeing in iOS codebases, with Swift 6.2 fixes.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.