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

Deadlock when self-referenting the same Mock from different threads #1899

Closed
boris-petrov opened this issue Feb 29, 2024 · 0 comments
Closed
Labels
Milestone

Comments

@boris-petrov
Copy link

boris-petrov commented Feb 29, 2024

Describe the bug

See the reproduction. It will deadlock. The problem seems (at least to me) to be in MockInteraction - there is a write lock that is acquired in accept and that causes the deadlock.

To Reproduce

class Foo {
    void bar() {
    }
}

...

def called = false
def foo
foo = Mock(Foo) {
    bar() >> {
        if (!called) {
            called = true
            Thread.start { foo.bar() }.join()
        }
    }
}
foo.bar()

Expected behavior

No deadlock

Actual behavior

Deadlock

Java version

21.0.2

Buildtool version

Gradle 8.6

What operating system are you using

Linux

Dependencies

Only Spock.

Additional context

Ported from #1882 (comment)

cc @leonard84

Vampire added a commit that referenced this issue Mar 6, 2024
@Vampire Vampire added this to the 2.4-M3 milestone Mar 7, 2024
Vampire added a commit that referenced this issue Mar 10, 2024
Vampire added a commit that referenced this issue Mar 16, 2024
leonard84 pushed a commit that referenced this issue Mar 17, 2024
leonard84 added a commit that referenced this issue Mar 17, 2024
This PR reverts the changes of PR #1885 and hopefully fixes #583, #1882,
and #1899 properly without the fallout of the previous PR.
All interaction handling stays synchronized, but the response generation
happens unsynchronized.

Co-authored-by: Leonard Brünings <leonard.bruenings@gradle.com>
@Vampire Vampire closed this as completed Mar 18, 2024
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