open-telemetry / opentelemetry-swift

OpenTelemetry API for Swift
https://opentelemetry.io/docs/instrumentation/swift/
Apache License 2.0
224 stars 146 forks source link

RecordEventsReadableSpan.swift memory corruption issue #366

Closed lfurukawa-ml closed 1 year ago

lfurukawa-ml commented 1 year ago

Hi community,

Ever since we updated OpentelemetrySDK’s version to 1.2.1, we are seeing an EXC_BAD_ACCESS error in the class RecordEventsReadableSpan.swift on our crash reporting tool, which seems to be a memory corruption issue.

OpentelemetrySDK’s release notes indicate there was a breaking change in the class RecordEventsReadableSpan.swift in version 1.2.0 (removal of the SwiftAtomics library)

Unfortunately, we've still not been able to trigger/reproduce the problem and the stacktrace is not very clear Could anyone help us figure out this issue? Here is the full stacktrace of the error:

Hardware Model:     iPhone12,1
Version:            10.243.0
Role:               Foreground
OS Version:         iOS 16.1.1
Exception Type:     EXC_BAD_ACCESS 
Exception Subtype:  KERN_INVALID_ADDRESS

EXC_BAD_ACCESS: Attempted to dereference garbage pointer 0xa080100010000000.

0  libswiftCore.dylib +0x3da130   __swift_release_dealloc
1  libswiftCore.dylib +0x3cb290   _swift_arrayDestroy
2  libswiftCore.dylib +0xd28f8    _DictionaryStorage.deinit
3  libswiftCore.dylib +0xd2920    _DictionaryStorage.__deallocating_deinit
4  libswiftCore.dylib +0x3da130   __swift_release_dealloc
5  MercadoLibre +0x204152c        RecordEventsReadableSpan.deinit (<compiler-generated>)
6  MercadoLibre +0x20415ac        RecordEventsReadableSpan.__deallocating_deinit (RecordEventsReadableSpan.swift)
7  libswiftCore.dylib +0x3da130   __swift_release_dealloc
8  libswiftCore.dylib +0x3cb290   _swift_arrayDestroy
9  libswiftCore.dylib +0xa2470    _ContiguousArrayStorage.__deallocating_deinit
10 libswiftCore.dylib +0x3da130   __swift_release_dealloc
11 MercadoLibre +0x20181d8        type metadata accessor for BatchSpanProcessor
12 libswiftCore.dylib +0x3da130   __swift_release_dealloc
13 libsystem_blocks.dylib +0x2120 __call_dispose_helpers_excp
14 libsystem_blocks.dylib +0x1d50 __Block_release
15 Foundation +0x67f60            -[NSBlockOperation dealloc]
16 MercadoLibre +0x20182dc        type metadata accessor for [OS_dispatch_source.TimerFlags]
17 libswiftCore.dylib +0x3da130   __swift_release_dealloc
18 libsystem_blocks.dylib +0x2120 __call_dispose_helpers_excp
lfurukawa-ml commented 1 year ago

We found out the culprit, the way we are capturing a custom span that's causing this crash.

nachoBonafonte commented 1 year ago

Thanks for the update