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-13878] Simple program crashes on exit possibly due to disorderly teardown (v5.3) #56276

Open
swift-ci opened this issue Nov 19, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13878
Radar rdar://problem/71589860
Original Reporter awal (JIRA User)
Type Bug
Environment

swift-5.3-RELEASE

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, RunTimeCrash
Assignee None
Priority Medium

md5: 632ca2b1f3a11eb0fbba76200cb815ef

Issue Description:

Running the program at bottom sometimes prints:

hello

Occasionally, it prints:

hello BlockExperiment world

However, the following crash consistently reproduces on a Mac and Linux machine:

 hello BlockExperiment/usr/bin/swift[0x51f95a4]
 /usr/bin/swift[0x51f719e]
 /usr/bin/swift[0x51f987c]
 /lib/x86_64-linux-gnu/libpthread.so.0(+0x12980)[0x7fc7c0650980]
 /usr/lib/swift/linux/libswiftCore.so(+0x40d2c4)[0x7fc7bc9642c4]
 /usr/lib/swift/linux/libswiftCore.so(+0x3fecc6)[0x7fc7bc955cc6]
 /usr/lib/swift/linux/libswiftCore.so(+0x3fe20b)[0x7fc7bc95520b]
 /usr/lib/swift/linux/libswiftCore.so(+0x3e456d)[0x7fc7bc93b56d]

(I thought there might be a race condition in my code, so I asked about it on StackOverflow: https://stackoverflow.com/questions/64903208/is-this-crash-in-a-swift-script-caused-by-a-race-condition)

To reproduce, run this script:

import Foundation

final class BlockRunner {
  var block: () -> ()
  init(_ b: @escaping () -> ()) { block = b }
  func run() { block() }
  deinit { print("Deinit: \(self)") }
}

final class BlockExperiment {
  func f() { 
    let queue = DispatchQueue(label: "Queue")
    let runner = BlockRunner { print("hello", self, "world") }
    queue.asyncAfter(deadline: .now() + 1) { runner.run() }
  }
  deinit { print("Deinit: \(self)") }
}

do {
  let e = BlockExperiment()
  e.f()
  RunLoop.current.run(until: Date() + 1 + 0.000000000000001)
}
@typesanitizer
Copy link

@swift-ci create

@eeckstein
Copy link
Member

The indeterministic output is easily explainable.

Though, I could not reproduce the crash (on Mac).
Could you reproduce the crash on Mac?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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. crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

4 participants