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

mutex.withLock does not reliably release lock on cancellation. #2380

Closed
Tilps opened this issue Nov 12, 2020 · 4 comments
Closed

mutex.withLock does not reliably release lock on cancellation. #2380

Tilps opened this issue Nov 12, 2020 · 4 comments
Labels

Comments

@Tilps
Copy link
Contributor

Tilps commented Nov 12, 2020

Playground here with close to minimal test case code.
https://pl.kotl.in/AGAyMv-l5

Running with Kotlin 1.4.10 it will output something like:
37,31,6
java.lang.IllegalStateException: Already locked by java.lang.Object@7c23b6a

With 1.3.72 it outputs:
26,26,0
java.lang.Exception

So it appears to be a regression.

The use of owner is not required, it just allows for the throwing of exception and counting failure frequency rather than hanging the entire test.

@Tilps
Copy link
Contributor Author

Tilps commented Nov 12, 2020

As a note

        mutex.withLock {
          	job.cancel()
        }
        job.join()

can be replaced with:

        mutex.withLock {
        }
        job.cancelAndJoin()

and it'll still fail, the failure frequency is a bit lower though.

@Tilps
Copy link
Contributor Author

Tilps commented Nov 16, 2020

I've debugged this and found a solution, I think... Will prepare PR.

@Tilps
Copy link
Contributor Author

Tilps commented Nov 16, 2020

I'll note this here, just a sight read of semaphore makes me suspect it has a similar problem. But I've not created a test case, so I won't create a separate issue for that yet.

@qwwdfsad qwwdfsad added the bug label Nov 17, 2020
@qwwdfsad
Copy link
Member

Fixed in 1.4.2, thanks!

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

No branches or pull requests

2 participants