Skip to content

Mock.On no longer acquires a lock #1210

Closed
@creachadair

Description

As part of the change in #1182 to change the Mock mutex to a pointer, the Mock.On method was changed to re-construct the mutex each time it is called.

This appears to have also introduced another regression (related to but in addition to #1208): Previously it was safe to call On concurrently with other operations on a Mock, but now because On resets that pointer, concurrent calls can race (observed in v1.7.4).

A small repro is attached to tickle the basic issue (go test -race should suffice).

Arguably it's silly for us to be calling On concurrently with other operations, but regrettably we have some code that relies on the ability to do so, and it worked before v1.7.4 but no longer does.

repro.zip

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions