Skip to content

Monitor should limit recursion #85128

@danmoseley

Description

@danmoseley

lock/Monitor supports recursion but does not seem to document or enforce a limit.

Right now it uses the object header up to 64 or so, then transitions to a sync block. That uses a 64 bit counter.

Correctness wise, it looks like the counter will just wrap (and release?) if code hits the limit -- given the size the chance of this is basically zero though.

But it might be interesting to pick a maximum recursion count that is less than ulong.MaxValue but greater than any plausible functioning code would need, then throw LockRecursionException when it's hit. This would expose any buggy code that is recursing without bound.

cc @kouvel from #34812 (comment)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions