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

[SR-15474] Unawaited async let crashes when it goes out of scope #57779

Open
swift-ci opened this issue Nov 11, 2021 · 3 comments
Open

[SR-15474] Unawaited async let crashes when it goes out of scope #57779

swift-ci opened this issue Nov 11, 2021 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features Linux Platform: Linux runtime The Swift Runtime standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-15474
Radar rdar://problem/85310493
Original Reporter hiimtmac (JIRA User)
Type Bug
Environment
Darwin hiimtmac.localdomain 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64

Xcode 13.1
Build version 13A1030d

Swift version 5.5.1 (swift-5.5.1-RELEASE)
Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, Concurrency, Linux, Runtime
Assignee @etcwilde
Priority Medium

md5: 8dd3461f2b203191394482dd01384ec5

Issue Description:

Allowing an async let to go out of scope without ever await ing it causes a crash.

The crash does not happen in LLDB unless the offending async let is within an await ed context.

The following code crashes on Linux, but not on macOS:

import Foundation

@main
struct SwiftBug {
    static func main() async throws {
        print("starting")
        
        try await iWillDie()

        print("done")
    }
    
    static func iWillDie() async throws {
        async let ones = doAsync()
        async let twos = doAsync()
        
        print(try await ones)
        if false {
            print(try await twos)
        }
    }
    
    static func doAsync() async throws -> [Int] {
        [1]
    }
}

I've created a repo that reproduces the crash: https://github.com/hiimtmac/swift-bug

LLDB trace:

root@531888c25919:/# lldb .build/debug/Run
(lldb) target create ".build/debug/Run"
Current executable set to '/.build/debug/Run' (x86_64).
(lldb) run
Process 19 launched: '/.build/debug/Run' (x86_64)
starting
[1]
Process 19 stopped
* thread #​4, name = 'Run', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
    frame #&#8203;0: 0x00007ffff75f2e50 libswiftCore.so`swift::metadataimpl::ValueWitnesses<swift::metadataimpl::SwiftRetainableBox>::destroy(swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*)
libswiftCore.so`swift::metadataimpl::ValueWitnesses<swift::metadataimpl::SwiftRetainableBox>::destroy:
->  0x7ffff75f2e50 <+0>: movq   (%rdi), %rdi
    0x7ffff75f2e53 <+3>: jmp    0x7ffff75efe30            ; swift_release
    0x7ffff75f2e58:      nopl   (%rax,%rax)
libswiftCore.so`swift::metadataimpl::ValueWitnesses<swift::metadataimpl::SwiftRetainableBox>::initializeWithCopy:
    0x7ffff75f2e60 <+0>: pushq  %r14
Target 0: (Run) stopped.
(lldb) bt
* thread #&#8203;4, name = 'Run', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
  * frame #&#8203;0: 0x00007ffff75f2e50 libswiftCore.so`swift::metadataimpl::ValueWitnesses<swift::metadataimpl::SwiftRetainableBox>::destroy(swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*)
    frame #&#8203;1: 0x00007ffff77b9db6 libswift_Concurrency.so`_asyncLet_finish_continuation(swift::AsyncContext*, void*) + 86
    frame #&#8203;2: 0x00007ffff77b86eb libswift_Concurrency.so`swift::runJobInEstablishedExecutorContext(swift::Job*) + 187
    frame #&#8203;3: 0x00007ffff77b8ce8 libswift_Concurrency.so`swift_job_run + 72
    frame #&#8203;4: 0x00007ffff701d435 libdispatch.so`_dispatch_continuation_pop + 357
    frame #&#8203;5: 0x00007ffff701d1e3 libdispatch.so`_dispatch_async_redirect_invoke + 211
    frame #&#8203;6: 0x00007ffff7029142 libdispatch.so`_dispatch_worker_thread + 514
    frame #&#8203;7: 0x00007ffff709a609 libpthread.so.0`start_thread + 217
    frame #&#8203;8: 0x00007ffff6ed9293 libc.so.6`__clone + 67
(lldb) 
@ktoso
Copy link
Member

ktoso commented Nov 11, 2021

@swift-ci create

@ktoso
Copy link
Member

ktoso commented Nov 11, 2021

Hmmm... I thought such issues were fixed; It definitely does not crash on today's recent focal nightly builds.

@etcwilde
Copy link
Member

etcwilde commented Feb 2, 2022

Hello, I am not seeing this bug anymore.

The above code is emitting the following output when built with the current top-of-tree:
```
starting
[1]
done
```

Please let us know if you're still seeing this issue.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features Linux Platform: Linux runtime The Swift Runtime standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants