OpenCombine icon indicating copy to clipboard operation
OpenCombine copied to clipboard

EXC_BAD_ACCESS when repeatedly using Future

Open ryanashcraft opened this issue 1 year ago • 3 comments

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:

ryanashcraft avatar Oct 12 '23 00:10 ryanashcraft

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.

tarbaiev-smg avatar Jan 22 '24 13:01 tarbaiev-smg

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!

ryanashcraft avatar Jan 22 '24 21:01 ryanashcraft

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

tarbaiev-smg avatar Jan 22 '24 23:01 tarbaiev-smg