Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on background queue .publisher effect subscription #3400

Closed
2 of 3 tasks
ivopintodasilva opened this issue Sep 19, 2024 · 4 comments
Closed
2 of 3 tasks

Crash on background queue .publisher effect subscription #3400

ivopintodasilva opened this issue Sep 19, 2024 · 4 comments
Labels
bug Something isn't working due to a bug in the library.

Comments

@ivopintodasilva
Copy link

ivopintodasilva commented Sep 19, 2024

Description

A crash is happening in the CurrentValueRelay.request function when I have a .publisher effect that is subscribed to on a background queue:

    var recordingsEffect: Effect<Action> {
        .publisher {
            recordingsService.recordings
                .removeDuplicates()
                .subscribe(on: backgroundQueue)
                .map { _ in
                    // ...
                    [:]
                }
                .receive(on: mainQueue)
                .map(Action.recordingsUpdated)
        }
    }

If I remove/comment the backgroundQueue subscription, this crash no longer happens.

⚠️ Also worth noting that it only started occurring in Xcode 16 and TCA v1.15.0 ⚠️

  • In TCA v1.15.0 and Xcode 15, works perfectly ✅
  • In TCA v1.14.0 and Xcode 16, works perfectly ✅

I also tried to isolate the issue in a sample project by simply having a .publisher effect that does some work in a background queue but there the crash was not reproducible either...

Will keep investigating and provide a barebones sample project with the crash replication as soon as i can.

Also worth sharing that the recordingsService.recordings is a TCA store publisher (store.publisher.recordings.eraseToAnyPublisher()).

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

The effect's inner publisher does some work in the background queue and sends an action back to the reducer (in the main queue) without crashing.

Actual behavior

image

Here's a stacktrace that i recovered from our crash reporter.

Reproducing project

Will append one as soon as I'm able to reproduce the issue in an isolated project.

The Composable Architecture version information

1.15.0

Destination operating system

iOS 18

Xcode version information

Xcode 16.0

Swift Compiler version information

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0
@ivopintodasilva ivopintodasilva added the bug Something isn't working due to a bug in the library. label Sep 19, 2024
@ivopintodasilva
Copy link
Author

ivopintodasilva commented Sep 19, 2024

After going through the commits in the v1.15.0 release, I was able to pin the issue down to commit 7c6fb26

// doesn't crash
.package(
    url: "https://github.com/pointfreeco/swift-composable-architecture",
    revision: "83ed1230412aa30cd84cbe1b5b8a4f298bce23aa"
),

// crashes
.package(
    url: "https://github.com/pointfreeco/swift-composable-architecture",
    revision: "7c6fb2670019d61e9040fab448dfce885b56c7fd"
),

@mbrandonw
Copy link
Member

Hi @ivopintodasilva, thank you very much for investigating this and providing so much information. The stack trace you provided seems quite similar to the problem described here in which an isolation invariant is broken. Would you have time to cook up a repro for us to investigate more deeply?

@ivopintodasilva
Copy link
Author

@mbrandonw will upload once i get some time to clean up my current project and make it focused on the crash 🙏

already tried to setup a small reproducible project but could replicate the crash so I might be missing something

@stephencelis
Copy link
Member

@ivopintodasilva I'm going to close this for now till we have a repro we can address, but please ping us and we can reopen when you share one! I'm also happy to convert this to a discussion if it turns out to not be a library bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working due to a bug in the library.
Projects
None yet
Development

No branches or pull requests

3 participants