Skip to content

[Improvements] Logger.cs — Initialize tears down old writer without draining in-flight writes #500

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info

File: src/Servy.Core/Logging/Logger.cs, line 94

Description:
InternalInitialize disposes the old _writer and creates a new one. If another thread is mid-Log() and has passed the if (_writer == null) return; check (line 285) but not yet entered the lock, it will try to write to the disposed writer.

The double-check at line 293 re-checks inside the lock, which prevents most races, but the outer null-check at line 285 is a stale read that could cache a non-null _writer reference that was just disposed.

Suggested fix:
Use a volatile read for _writer at line 285, or replace the double-check with a full lock acquisition. Alternatively, drain in-flight writes before disposing.

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