Skip to content

Data race detected by thread sanitizer on WhisperKit.progress instance variable. #331

@clindsay3

Description

@clindsay3

The progress instance variable on WhisperKit is not being properly protected from data races.

Since WhisperKit is not actor-isolated, access to progress in the runTranscribeTask method can occur on multiple threads.

When I run in my own app and enable the thread sanitizer in the scheme diagnostic options, it detects this section as a data race:

if progress.isFinished {
   // Reset progress if it is completed
   progress = Progress()
}

Here's the detailed thread sanitizer report:

WARNING: ThreadSanitizer: data race (pid=51838)
  Read of size 8 at 0x000106e68c58 by thread T29:
    #0 WhisperKit.WhisperKit.progress.getter : __C.NSProgress <null> (TranscrybeCore:arm64+0x2c5428)
    #1 (5) suspend resume partial function for WhisperKit.WhisperKit.runTranscribeTask(audioArray: Swift.Array<Swift.Float>, decodeOptions: Swift.Optional<WhisperKit.DecodingOptions>, callback: Swift.Optional<(WhisperKit.TranscriptionProgress) -> Swift.Optional<Swift.Bool>>) async throws -> Swift.Array<WhisperKit.TranscriptionResult> <null> (TranscrybeCore:arm64+0x2fac20)
    #2 swift::runJobInEstablishedExecutorContext(swift::Job*) <null> (libswift_Concurrency.dylib:arm64e+0x5c450)

  Previous write of size 8 at 0x000106e68c58 by thread T35:
    #0 (5) suspend resume partial function for WhisperKit.WhisperKit.runTranscribeTask(audioArray: Swift.Array<Swift.Float>, decodeOptions: Swift.Optional<WhisperKit.DecodingOptions>, callback: Swift.Optional<(WhisperKit.TranscriptionProgress) -> Swift.Optional<Swift.Bool>>) async throws -> Swift.Array<WhisperKit.TranscriptionResult> <null> (TranscrybeCore:arm64+0x2fad34)
    #1 swift::runJobInEstablishedExecutorContext(swift::Job*) <null> (libswift_Concurrency.dylib:arm64e+0x5c450)

  Location is heap block of size 712 at 0x000106e68a00 allocated by main thread:
    #0 malloc <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x55fb4)
    #1 _malloc_type_malloc_outlined <null> (libsystem_malloc.dylib:arm64e+0x1da80)
    #2 swift::runJobInEstablishedExecutorContext(swift::Job*) <null> (libswift_Concurrency.dylib:arm64e+0x5c450)
    #3 __debug_main_executable_dylib_entry_point <null> (Transcrybe.debug.dylib:arm64+0x7ed0)
    #4 <null> <null> (0x000193a1ab4c)

  Thread T29 (tid=6180198, running) is a GCD worker thread

  Thread T35 (tid=6180204, running) is a GCD worker thread

SUMMARY: ThreadSanitizer: data race (/Users/chris/Library/Developer/Xcode/DerivedData/Transcrybe-hbenxjemepmsovdjjuucnlyerfnc/Build/Products/Debug/Transcrybe.app/Contents/Frameworks/TranscrybeCore.framework/Versions/A/TranscrybeCore:arm64+0x2c5428) in WhisperKit.WhisperKit.progress.getter : __C.NSProgress+0x38

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions