Skip to content

Balance OperationQueue retain/release #2779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2020

Conversation

lxbndr
Copy link
Contributor

@lxbndr lxbndr commented Apr 29, 2020

Operation._queue internal property does release stored value on every getter call. In most scenarios it is accessed exactly once, and balanced by "leaking" same value to Thread Specific storage. But under some conditions _queue is accessed twice, and crash is inevitable.

I strongly believe that property accessor should not release its value. Kind of typo for me. Operation already has the pair of _adopt(queue:schedule:)/_invalidateQueue() functions intended to manage ownership of queue, and they are used in proper places.

This patch

  • prevents releasing of stored value in Operation._queue property getter
  • balances retain count after current queue removed from thread-specific storage
  • enables all available Operation/OperationQueue tests (including lifecycle test to make sure Queue not leaks with this change)
  • makes test_OperationWaitUntilFinished stable
  • extends test_OperationCount to cover more conditions

cc @compnerd @spevans @millenomi

- prevent releasing of stored value in `Operation._queue` property getter
- balance retain count after current queue removed from thread-specific storage
- make test_OperationWaitUntilFinished stable
- extend test_OperationCount
@spevans
Copy link
Contributor

spevans commented Apr 30, 2020

@swift-ci test linux

1 similar comment
@spevans
Copy link
Contributor

spevans commented May 1, 2020

@swift-ci test linux

@compnerd
Copy link
Member

compnerd commented May 2, 2020

@compnerd
Copy link
Member

compnerd commented May 2, 2020

Windows build looks good as well. This seems correct to me.

@compnerd compnerd merged commit 14f0c8a into swiftlang:master May 2, 2020
@lxbndr lxbndr deleted the operation-queue-overrelease branch May 2, 2020 18:49
@broadwaylamb
Copy link
Contributor

broadwaylamb commented Jun 24, 2020

Will this be able to make it into Swift 5.3? Seems like a pretty nasty bug.

@millenomi @parkera

@spevans
Copy link
Contributor

spevans commented Jun 24, 2020

@broadwaylamb I created #2831 to backport some OperationQueue fixes to 5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants