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

Tests randomly failing after updating to 0.28 #18

Open
arg0d opened this issue Sep 13, 2024 · 3 comments
Open

Tests randomly failing after updating to 0.28 #18

arg0d opened this issue Sep 13, 2024 · 3 comments

Comments

@arg0d
Copy link

arg0d commented Sep 13, 2024

https://github.com/NordSecurity/uniffi-rs/actions/runs/10850215015/job/30111115697

@arg0d
Copy link
Author

arg0d commented Jan 3, 2025

Trying to debug this right now, it seems to be coming from async Swift code. I can't reproduce this locally, only in Github pipeline. Right now the fail happens in uniffi-rs/fixtures/ext-types/proc-macro-lib/tests/bindings/test_imported_types.swift, but I fear it may affect all other async tests. According to some quick Google'ing ant ChatGPT, blocking the main thread may be "undefined behaviour". I'm not sure why this only happens in the pipeline. I don't think it's related to any changes in this fork, because right now there are no changes related to async code, or Swift code at all.

Originally the test uses DispatchGroup to synchronize main thread with async task. I've tried to use DispatchSemaphore, but I'm getting the same result. The async task seemingly crashes the program upon signaling. The main thread seems to run to completion, but the program crashes.

In the Swift test file, the async task does not print BBBBB 6

let semaphore = DispatchSemaphore(value: 0)
print("AAAAAAAAAAAAAAAAAAAAAAA 6.1")
print("AAAAAAAAAAAAAAAAAAAAAAA 6.2")
Task {
    print("BBBBBBBBBBBBBBBBBBBB 1")
    // This async function comes from the `uniffi-one` crate
    let uniffiOneEnum = await getUniffiOneAsync()
    print("BBBBBBBBBBBBBBBBBBBB 2")
    assert(uniffiOneEnum == UniffiOneEnum.one)
    print("BBBBBBBBBBBBBBBBBBBB 3")

    // This async function comes from the `proc-macro-lib` crate
    let uniffiOneType = await getUniffiOneTypeAsync(t: UniffiOneType(sval: "hello"))
    print("BBBBBBBBBBBBBBBBBBBB 4")
    assert(uniffiOneType.sval == "hello")
    print("BBBBBBBBBBBBBBBBBBBB 5")

    semaphore.signal()
    print("BBBBBBBBBBBBBBBBBBBB 6")
}
print("AAAAAAAAAAAAAAAAAAAAAAA 6.3")
semaphore.wait()
print("AAAAAAAAAAAAAAAAAAAAAAA 6.4")

print("AAAAAAAAAAAAAAAAAAAAAAA 7")
fflush(stdout)
AAAAAAAAAAAAAAAAAAAAAAA 1
AAAAAAAAAAAAAAAAAAAAAAA 2
AAAAAAAAAAAAAAAAAAAAAAA 3
AAAAAAAAAAAAAAAAAAAAAAA 4
AAAAAAAAAAAAAAAAAAAAAAA 5
AAAAAAAAAAAAAAAAAAAAAAA 6
AAAAAAAAAAAAAAAAAAAAAAA 6.1
AAAAAAAAAAAAAAAAAAAAAAA 6.2
AAAAAAAAAAAAAAAAAAAAAAA 6.3
BBBBBBBBBBBBBBBBBBBB 1
BBBBBBBBBBBBBBBBBBBB 2
BBBBBBBBBBBBBBBBBBBB 3
BBBBBBBBBBBBBBBBBBBB 4
BBBBBBBBBBBBBBBBBBBB 5
AAAAAAAAAAAAAAAAAAAAAAA 6.4
AAAAAAAAAAAAAAAAAAAAAAA 7
AAAAAAAAAAAAAAAAAAAAAAA 8
AAAAAAAAAAAAAAAAAAAAAAA 9
AAAAAAAAAAAAAAAAAAAAAAA 10
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.

@arg0d
Copy link
Author

arg0d commented Jan 4, 2025

Looks like timing related issue. Adding Thread.sleep(forTimeInterval: 1) at the end of main thread "fixes" the issue. I'm guessing there is some issue with outstanding async tasks running in the background when main thread exits. The sleep in main thread avoids this issue. I still don't understand why I can't reproduce this on my computer, the issue only happens in Github CI.

@arg0d
Copy link
Author

arg0d commented Jan 6, 2025

I tried to remove uniffi related calls from the async task, and the program stops crashing. So it's somehow uniffi related?

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

1 participant