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

EXC_BAD_ACCESS when repeatedly using Future #245

Open
ryanashcraft opened this issue Oct 12, 2023 · 3 comments
Open

EXC_BAD_ACCESS when repeatedly using Future #245

ryanashcraft opened this issue Oct 12, 2023 · 3 comments

Comments

@ryanashcraft
Copy link

Hello folks. I am investigating an issue where I can trigger iOS to crash with an EXC_BAD_ACCESS when repeatedly using Futures.

From OpenCombineTests.swift in my sample project repo:

import XCTest
import OpenCombine

private class Item {}

final class OpenCombineTests: XCTestCase {
    func testBadAccessSimplified() async {
        let item = await Future<Item, Never> { promise in
            DispatchQueue.global().async {
                promise(.success(Item()))
            }
        }
        .value
    }
}

If I run this test case repeatedly until failure with enough iterations (10000+), an EXC_BAD_ACCESS will (most likely) occur. See screenshot:

opencombine

For context, this behavior also occurs when running with Apple's Combine. I haven't had much luck finding anyone who can help me understand what's going on here, so I am creating an issue here as I figure you folks might be able to help. 🙏

Notes:

  • I have also been able to reproduce this issue a normal application lifecycle context
  • As far as I can tell, the issue seems limited to Combine or OpenCombine usage. I have not been able to reproduce similar behavior with any other async library/solution.

Related links:

@tarbaiev-smg
Copy link

I think the issue might be caused by accessing the Future's result from the Conduit from outside of the Future's lock here. Strangely neither the Address nor Thread sanitizers are able to catch this.

@ryanashcraft
Copy link
Author

I think the issue might be caused by accessing the Future's result from the Conduit from outside of the Future's lock here. Strangely neither the Address nor Thread sanitizers are able to catch this.

Hi @tarbaiev-smg. To clarify, are you thinking this issue is a bug with OpenCombine, or with my usage of Future? If it's the latter, can you please help me understand exactly what I'm doing wrong? Thank you!

@tarbaiev-smg
Copy link

Definitely the implementation, both Combine and OpenCombine. I spent a weekend investigating this exact issue.

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

No branches or pull requests

2 participants