Skip to content

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

@boris-petrov

Description

@boris-petrov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions