Skip to content

Logger.Listeners and Logger.Sources are not thread safe #655

@ManlyMarco

Description

@ManlyMarco

What happened?

Adding or removing Logger.Listeners and Logger.Sources can cause exceptions if some other thread is currently enumerating these lists, e.g. when calling Logger.Log. This usually causes unexpected crashes in whatever code was trying to log something at an unfortunate time.

Steps to reproduce

  1. Create a thread that adds and removes a Logger.Listeners in a loop.
  2. Call Logger.Log on a plugin's logger in a loop.
  3. Eventually a crash will happen.

It's possible to 100% get this to happen by trying to remove a listener from Logger.Listeners within a ILogListener.LogEvent, but that's a bit of a different issue.

BepInEx Distribution

Stable from GitHub

Log outputs

N/A

Environment

- OS: Any
- BepInEx: 5.4.21
- Game: Any

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions