Description
Description
When Thread Sanitizer is enabled, an apparent miscompile takes place in NIOWebSocket.WebSocketMaskingKey.random()
, causing a write to an invalid address on the second invocation of the method on macOS and on the first invocation thereof on Linux, in all current and development Swift versions (see below for specifics). The issue does not appear when no sanitizer is enabled, nor with --sanitize=address
.
Steps to reproduce
This is the most minimal reproducer I could find (simplified post-merge of apple/swift-nio#2433):
git clone https://github.com/apple/swift-nio.git && cd swift-nio
swift test --sanitize=thread --filter=testRandomMaskingKeyIsNotAlwaysZeroWithDefaultGenerator
Expected behavior
The tests pass.
Environment
Failure observed against:
- macOS 13.4 (22F66), Xcode 14.3 (Build version 14E222b), Swift version
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)\nTarget: arm64-apple-macosx13.0
swift:5.8-jammy
Docker image, Swift versionswift-5.8-RELEASE
swiftlang/swift:nightly-5.9-jammy
Docker image, Swift versionswift-5.9-DEVELOPMENT-SNAPSHOT-2023-05-22-a
swiftlang/swift:nightly-main-jammy
Docker image, Swift versionswift-DEVELOPMENT-SNAPSHOT-2023-05-20-a
Additional Context
Output from the crash in each test environment is attached (note: these were made before the new test was added to NIO and thus refer to the tweaked versions of the existing tests - the logs are otherwise identical using the new tests):
tsan-crash-macos.txt
tsan-crash-swift-5.8-jammy.txt
tsan-crash-swift-nightly-5.9-jammy.txt
tsan-crash-swift-nightly-main-jammy.txt