Skip to content

RotatingStreamWriter.Rotate: redundant nested lock — caller already holds _lock #164

@Christophe-Rogiers

Description

@Christophe-Rogiers

Issue

The Rotate() method acquires _lock around CloseWriter():

private void Rotate()
{
    // ...
    lock (_lock)
    {
        CloseWriter();
    }
}

However, Rotate() is only called from CheckRotation(), which is called from WriteLine() and Write() — both of which already hold _lock. C#'s Monitor is reentrant so this doesn't deadlock, but the redundant lock is misleading and suggests the locking strategy isn't well-defined.

Suggested fix

Remove the inner lock (_lock) in Rotate() and add a comment that the caller must hold the lock.

File

src/Servy.Core/IO/RotatingStreamWriter.cs — lines 326-334

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions