Skip to content

Crash in destroy for AsyncChain2Sequence? #69367

@mansbernhardt

Description

@mansbernhardt

Using 0.1.0 of the library I sometimes get a crash (EXC_BAD_ACCESS (code=1, address=0xf2575c505790)) in iterator next(), see example of call stack below (caught from Xcode while debugging). Any ideas what might cause this? In the call stack below I was using a type erasers from: https://github.com/pointfreeco/swift-concurrency-extras, such as:

extension AsyncThrowingStream where Failure == Error {
  /// Produces an `AsyncThrowingStream` from an `AsyncSequence` by consuming the sequence till it
  /// terminates, rethrowing any failure.
  ///
  /// - Parameter sequence: An async sequence.
  public init<S: AsyncSequence>(_ sequence: S) where S.Element == Element {
    var iterator: S.AsyncIterator?
    self.init {
      if iterator == nil {
        iterator = sequence.makeAsyncIterator()
      }
      return try await iterator?.next()
    }
  }
#0	0x000000019035520c in _swift_release_dealloc ()
apple/swift-async-algorithms#1	0x0000000190355f00 in bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>>::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) ()
apple/swift-async-algorithms#2	0x00000001020a1eb4 in destroy for AsyncChain2Sequence ()
apple/swift-async-algorithms#3	0x00000001020de454 in destroy for AsyncRemoveDuplicatesSequence ()
apple/swift-async-algorithms#4	0x00000001020590c8 in ___lldb_unnamed_symbol212959 ()
apple/swift-async-algorithms#5	0x0000000190355224 in _swift_release_dealloc ()
apple/swift-async-algorithms#6	0x0000000190355f00 in bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>>::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) ()
apple/swift-async-algorithms#7	0x000000021f85c23c in closure apple/swift-async-algorithms#1 in closure apple/swift-async-algorithms#1 in AsyncStream.init(unfolding:onCancel:) ()
apple/swift-async-algorithms#8	0x000000021f873df0 in partial apply for closure apple/swift-async-algorithms#1 in closure apple/swift-async-algorithms#1 in AsyncStream.init(unfolding:onCancel:) ()
apple/swift-async-algorithms#9	0x000000021f851b20 in withTaskCancellationHandler<τ_0_0>(operation:onCancel:) ()
apple/swift-async-algorithms#10	0x000000021f84ffa0 in withTaskCancellationHandler<τ_0_0>(operation:onCancel:) ()
apple/swift-async-algorithms#11	0x000000021f85bd74 in closure apple/swift-async-algorithms#1 in AsyncStream.init(unfolding:onCancel:) ()
apple/swift-async-algorithms#12	0x000000021f873db0 in partial apply for closure apple/swift-async-algorithms#1 in AsyncStream.init(unfolding:onCancel:) ()
apple/swift-async-algorithms#13	0x000000021f85c4c8 in AsyncStream.Iterator.next() ()
apple/swift-async-algorithms#14	0x000000021f873da4 in protocol witness for AsyncIteratorProtocol.next() in conformance AsyncStream<τ_0_0>.Iterator ()
apple/swift-async-algorithms#15	0x000000021f83a954 in AsyncCompactMapSequence.Iterator.next() ()
apple/swift-async-algorithms#16	0x000000021f873e00 in protocol witness for AsyncIteratorProtocol.next() in conformance AsyncCompactMapSequence<τ_0_0, τ_0_1>.Iterator ()
apple/swift-async-algorithms#17	0x000000021f865734 in dispatch thunk of AsyncIteratorProtocol.next() ()
apple/swift-async-algorithms#18	0x0000000102058e14 in closure apple/swift-async-algorithms#1 in AsyncStream.init<τ_0_0>(_:) at /Users/mansbernhardt/Library/Developer/Xcode/DerivedData/Gigset-gkrmpjneavqivdheptpucovbtxjv/SourcePackages/checkouts/swift-concurrency-extras/Sources/ConcurrencyExtras/AsyncStream.swift:59
apple/swift-async-algorithms#19	0x00000001020591b0 in partial apply for closure apple/swift-async-algorithms#1 in AsyncStream.init<τ_0_0>(_:) ()
apple/swift-async-algorithms#20	0x000000021f85c144 in closure apple/swift-async-algorithms#1 in closure apple/swift-async-algorithms#1 in AsyncStream.init(unfolding:onCancel:) ()
apple/swift-async-algorithms#21	0x000000021f873df0 in partial apply for closure apple/swift-async-algorithms#1 in closure apple/swift-async-algorithms#1 in AsyncStream.init(unfolding:onCancel:) ()
apple/swift-async-algorithms#22	0x000000021f851b20 in withTaskCancellationHandler<τ_0_0>(operation:onCancel:) ()
apple/swift-async-algorithms#23	0x000000021f84ffa0 in withTaskCancellationHandler<τ_0_0>(operation:onCancel:) ()
apple/swift-async-algorithms#24	0x000000021f85bd74 in closure apple/swift-async-algorithms#1 in AsyncStream.init(unfolding:onCancel:) ()
apple/swift-async-algorithms#25	0x000000021f873db0 in partial apply for closure apple/swift-async-algorithms#1 in AsyncStream.init(unfolding:onCancel:) ()
apple/swift-async-algorithms#26	0x000000021f85c4c8 in AsyncStream.Iterator.next() ()
apple/swift-async-algorithms#27	0x000000021f873da4 in protocol witness for AsyncIteratorProtocol.next() in conformance AsyncStream<τ_0_0>.Iterator ()
apple/swift-async-algorithms#28	0x000000021f865734 in dispatch thunk of AsyncIteratorProtocol.next() ()
apple/swift-async-algorithms#29	0x0000000102059fd8 in closure apple/swift-async-algorithms#1 in AsyncThrowingStream<>.init<τ_0_0>(_:) at /Users/mansbernhardt/Library/Developer/Xcode/DerivedData/Gigset-gkrmpjneavqivdheptpucovbtxjv/SourcePackages/checkouts/swift-concurrency-extras/Sources/ConcurrencyExtras/AsyncThrowingStream.swift:12
apple/swift-async-algorithms#30	0x000000010205a340 in partial apply for closure apple/swift-async-algorithms#1 in AsyncThrowingStream<>.init<τ_0_0>(_:) ()
apple/swift-async-algorithms#31	0x000000021f85d5ec in closure apple/swift-async-algorithms#1 in closure apple/swift-async-algorithms#1 in AsyncThrowingStream.init<>(unfolding:) ()
apple/swift-async-algorithms#32	0x000000021f873de4 in partial apply for closure apple/swift-async-algorithms#1 in closure apple/swift-async-algorithms#1 in AsyncThrowingStream.init<>(unfolding:) ()
apple/swift-async-algorithms#33	0x000000021f851b20 in withTaskCancellationHandler<τ_0_0>(operation:onCancel:) ()
apple/swift-async-algorithms#34	0x000000021f84ffa0 in withTaskCancellationHandler<τ_0_0>(operation:onCancel:) ()
apple/swift-async-algorithms#35	0x000000021f85d19c in closure apple/swift-async-algorithms#1 in AsyncThrowingStream.init<>(unfolding:) ()
apple/swift-async-algorithms#36	0x000000021f873dd4 in partial apply for closure apple/swift-async-algorithms#1 in AsyncThrowingStream.init<>(unfolding:) ()
apple/swift-async-algorithms#37	0x000000021f85d9b0 in AsyncThrowingStream.Iterator.next() ()
apple/swift-async-algorithms#38	0x00000001023d54a0 in closure apple/swift-async-algorithms#3 in AsyncView.body.getter at /Users/mansbernhardt/dev/gigset-apple4/gigset/Sources/ViewUtilities/AsyncView.swift:30
apple/swift-async-algorithms#39	0x00000001023d68d8 in partial apply for closure apple/swift-async-algorithms#3 in AsyncView.body.getter ()

We are also seeing Intel Macs running 12.x with this crash logs (release builds), not sure if they might be related:

Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 4 Illegal instruction: 4

Thread 4 Crashed:
0   libswiftCore.dylib            	0x00007ff828033245 _assertionFailure(_:_:file:line:flags:) + 421 (AssertCommon.swift:132)
1   libswift_Concurrency.dylib    	0x00007ffb34060b64 AsyncStream._Storage.next(_:) + 532 (AsyncStreamBuffer.swift:253)
2   libswift_Concurrency.dylib    	0x00007ffb340735ec partial apply for closure apple/swift-async-algorithms#2 in AsyncStream._Storage.next() + 188 (<compiler-generated>:0)
3   libswift_Concurrency.dylib    	0x00007ffb340742e1 thunk for @callee_guaranteed @async () -> (@out A?) + 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions