8000 Attempt to obtain new locks without retrying transaction in ZSTM by kyri-petrou · Pull Request #9221 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Attempt to obtain new locks without retrying transaction in ZSTM #9221

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 4 commits into from
Sep 27, 2024

Conversation

kyri-petrou
Copy link
Contributor

/fixes #9215

The issue is that in cases where a transaction creates ZSTMs internally, if there is contention and we reach the MaxRetries section, the ZSTM loop will keep retrying because the locks will be changing on each iteration.

With this PR we attempt to obtain the diff in locks while we still hold the "outer" locks. This fixes the issue but is also more performant as we're not retrying the entire transaction in cases where we can acquire the additional locks

test("doesn't deadlock under concurrency when transactions create new ZSTMs - i9215") {
def transaction(arr: TArray[String]) =
ZSTM.suspend {
Thread.sleep(1) // Force ZSTM lock contention
Copy link
Member

Choose a reason for hiding this comment

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

Looks like it fails with Scala.js despite the except aspect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aghh the except part is for nonFlaky. Seems that ScalaJS doesn't like the Thread.sleep part, I'll move the test to be run for JVM/Native only

@ghostdogpr
Copy link
Member

Native doesn't like it either? Or it's just flaky?

@kyri-petrou
Copy link
Contributor Author

Native doesn't like it either? Or it's just flaky?

Seems like an issue with GC. I changed the test to run on JVM only for the time being

ghostdogpr
ghostdogpr approved these changes Sep 26, 2024
< 8375 div class="ml-md-2 mt-md-0 mt-2 flex-shrink-0"> View reviewed changes
@kyri-petrou kyri-petrou merged commit ee4cd6a into zio:series/2.x Sep 27, 2024
18 checks passed
@kyri-petrou kyri-petrou deleted the fix-zstm-rare-deadlock branch February 10, 2025 08:28
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.

STM transaction retry loop (regression in 2.1.8)
2 participants
0