unsignedapps / Vexil

Vexil (named for Vexillology) is a Swift package for managing feature flags (also called feature toggles) in a flexible, multi-provider way.
https://vexil.unsignedapps.com
MIT License
115 stars 12 forks source link

Occasional hang if used in an extension that is initialised multiple times #103

Closed bok- closed 2 years ago

bok- commented 2 years ago

Vexil version: 2.2.0 Swift version: swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) Environment: Xcode 13.2.1 – Xcode 13.4

✅ Checklist

🔢 Description

When using Vexil with an extension that could see the Process initialised multiple times (such as Apple Pay), the following line occasionally hangs:

private func setupSnapshotPublishing (keys: Set<String>, sendImmediately: Bool, changedSources: [String]? = nil) {
    guard self.shouldSetupSnapshotPublishing else { return }

    self.cancellables.forEach { $0.cancel() }
    self.cancellables.removeAll()                        // hang here

This hang does not occur if we remove the manual calls to AnyCancellable.cancel(). As noted in [AnyCancellable](https://developer.apple.com/documentation/combine/anycancellable#:~:text=An%20AnyCancellable%20instance%20automatically%20calls%20cancel()%20when%20deinitialized) the cancel() function is called on deinit anyway, so the manual call to cancel() is not required. We should remove it.