Skip to content

chan: hung up occasionally due to uninitiated mutex #1133

@MeteorsLiu

Description

@MeteorsLiu

Problem

When calling exec.Command.Run(), it hung up occasionally.

exec.Command("...").Run()

Investigate

We injected some debug output codes to llgo runtime, and found these situations.

Image

When it hung up, it prints

recv {2 <nil>}
after minus {1 <nil>}
sent back {1 <nil>}
recv {1 <nil>}
after minus {0 <nil>}
recv {2 <nil>}
recv {2 <nil>}
after minus {1 <nil>}
after minus {1 <nil>}
sent back {1 <nil>}
sent back {1 <nil>}

In this output, we found the second recv is not expected.

We suspected that there's something wrong about channel implement.

So we injected some debug codes to z_chan.go

Image

And we found these strange output, in these codes, Cond.Wait should wait for someone, however, it skips waiting, and keep busy waitting.

Image

Then, we printed the output of Wait, and found it returnsEINVAL, which means we passed an uninitiated mutex to it, casuing it busy waiting.

It also explains the reason why the result of recv is wrong, because the uninitiated mutex cannot protect critical sections causing the data racy.

Conclusion

The mutex of channel is uninitiated.

Metadata

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