Skip to content
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

Failing Test Case: Delayed Lifetime deinit deadlocking sendLock. (#137) #136

Closed
wants to merge 1 commit into from

Conversation

andersio
Copy link
Member

@andersio andersio commented Nov 30, 2016

Related issue: #135

Cause

  1. A strong release atomically drops the refCount to 0. But deinitialization does not start right away.
  2. A weak retain - the binding's observer closure in this case - manages to increment the refCount before the strong release flags the object as deallocating.
  3. The deinitialization is thus delayed until exiting the scope of the observer closure, i.e. within the sendLock.

What's affected?

Everything in the following pattern:

signal
    .take(during: object.lifetime)
    .observeValues { [weak object] _ in }

Note

The test case would not fail in a uniprocessor environment.

Possible Solution

Allowing completed to be recursively sent like interrupted seems the only way, since:

  1. We have no autoreleasepool for Swift objects.
  2. The order cannot be controlled.

@andersio andersio added the bug label Nov 30, 2016
@andersio
Copy link
Member Author

andersio commented Nov 30, 2016

NSRecursiveLock unfortunately seems the easiest solution to this race condition. Handling completed like interrupted is like opening Pandora's box, racing with Swift's deallocation routines concurrently, and having malloc broken or polluted somehow.

Got something up... Seemed like it was suffering from corrupted state before...

@andersio andersio changed the title Failing Test Case: Delayed Lifetime deinit deadlocking sendLock. Failing Test Case: Delayed Lifetime deinit deadlocking sendLock. (#137) Dec 2, 2016
@andersio andersio closed this Dec 2, 2016
@andersio andersio deleted the deadlock-testcase branch December 2, 2016 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant