Skip to content

(ios) Revert: Integrate Touchlab's SKIE#551

Merged
dpad85 merged 1 commit intomasterfrom
revert-skie
Apr 12, 2024
Merged

(ios) Revert: Integrate Touchlab's SKIE#551
dpad85 merged 1 commit intomasterfrom
revert-skie

Conversation

@robbiehanson
Copy link
Contributor

We were experiencing app freezes in production. The root cause of the problem was Touchlab's SKIE. In particular, an unexpected quirk of the SKIE implementation.

Consider this Swift code:

Task { @MainActor in
   self.fetched = try await paymentsManager.fetcher.getPayment(
      row: row,
      options: PaymentCell.fetchOptions
   )
}

Here we're calling a suspend function in Kotlin (getPayment) from Swift. Now it has always been the case this must be done on the main thread (e.g. MainActor). In fact if you tried from a background thread, Kotlin would throw an exception. It has also been the case that getPayment executes on the main thread.

In recent versions of Kotlin, this main-thread restriction could be removed with a flag.

It appears that SKIE automatically sets this flag. From their docs

Another limitation is that these suspend functions can only be called from the main thread. This limitation can be solved without SKIE by passing a special configuration flag to the compiler. However, SKIE adds this support out of the box.

The end result is that multiple instances of getPayment are running simultaneously on different background threads, our built-in Cache is getting corrupted, and the linked-list ends up with cycles leading to infinite loops in certain situations.

It's relatively easy to solve this one particular bug. But the bigger issue is that I don't know what other issues this problem might cause. And time is needed to further research the issue.

@robbiehanson robbiehanson requested a review from dpad85 April 11, 2024 22:15
Copy link
Member

@dpad85 dpad85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The end result is that multiple instances of getPayment are running simultaneously on different background threads, our built-in Cache is getting corrupted, and the linked-list ends up with cycles leading to infinite loops in certain situations.

It's relatively easy to solve this one particular bug. But the bigger issue is that I don't know what other issues this problem might cause. And time is needed to further research the issue.

Makes sense, the SyncTxManager could be another cause, and there may be others. Will make a build ASAP.

@dpad85 dpad85 merged commit 098ece0 into master Apr 12, 2024
@dpad85 dpad85 deleted the revert-skie branch April 12, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants