Skip to content

Conversation

@ktoso
Copy link
Contributor

@ktoso ktoso commented Jul 8, 2024

Description: Since we introduced proper ownership of task executors, they are now released and retained. The problem appears with a dispatch_queue_t which conforms to TaskExecutor being passed to Task initializer and retains work okey because it is __owned. However, upon destroy we swift_released the executor reference, which is incorrect as we must be using object specific release methods -- in this case the safe way to support all kinds of objects is swift_unknownObjectRelease
Scope/Impact: Unbreaks users of task executors who use a raw dispatchqueue as the executor.
Risk: Low, changes swift_release to swift_unknownObjectRelease which is stricly more accepting.
Testing: Verified in a reproducer project
Reviewed by: @mikeash

Original PR: #75059
Radar: rdar://131151645

…ase them

Since we introduced proper ownership of task executors, they are now
released and retained. The problem appears with a dispatch_queue_t which
conforms to TaskExecutor being passed to Task initializer and retains
work okey because it is __owned. However, upon destroy we swift_released
the executor reference, which is incorrect as we must be using object
specific release methods -- in this case the safe way to support all
kinds of objects is `swift_unknownObjectRelease`

resolves rdar://131151645
@ktoso ktoso requested a review from a team as a code owner July 8, 2024 15:27
@ktoso
Copy link
Contributor Author

ktoso commented Jul 8, 2024

@swift-ci please test

@ktoso
Copy link
Contributor Author

ktoso commented Jul 9, 2024

Added a test to cover the fixed situation

@ktoso ktoso added concurrency Feature: umbrella label for concurrency language features 🍒 release cherry pick Flag: Release branch cherry picks swift 6.0 labels Jul 9, 2024
@ktoso
Copy link
Contributor Author

ktoso commented Jul 9, 2024

@swift-ci please test

@ktoso ktoso enabled auto-merge July 9, 2024 07:24
@ktoso ktoso merged commit bb44c63 into swiftlang:release/6.0 Jul 9, 2024
@ktoso ktoso deleted the pick-wip-avoid-wrong-release-on-non-swift-objects branch July 9, 2024 13:08
// This test specifically checks that our reference counting accounts for existence of
// objective-c types as TaskExecutors -- which was a bug where we'd swift_release
// obj-c excecutors by accident (rdar://131151645).
final class NSQueueTaskExecutor: NSData, TaskExecutor, @unchecked Sendable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Swift refcounting on this class will end up working on the field after the end of the instance, since instances of this object will just contain a single pointer. Presumably this does fail in practice, but it might be good to make it more certain by adding a field with a value that will provoke a crash. var dummy = 0 or var dummy = -1 ought to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

concurrency Feature: umbrella label for concurrency language features 🍒 release cherry pick Flag: Release branch cherry picks swift 6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants