Skip to content

MemoryCache's unhandled exception handler disposes a timer that takes a lock and can lead to deadlock #102666

Open
@kouvel

Description

@kouvel

Below is an example of a deadlock that was seen.

Thread 1:

  • Enters a concurrent queue's cross-segment lock here
  • OOM exception occurs here in array allocation
  • MemoryCache's unhandled exception handler runs, disposes stats, disposes timer, which tries to enter a TimerQueue lock here and blocks because Thread 2 holds the lock

Thread 2:

  • Enters the TimerQueue lock here
  • Tries to queue a timer callback, which tries to enter the concurrent queue's cross-segment lock here and blocks because Thread 1 holds the lock

The two threads are deadlocked. Unhandled exceptions can occur in arbitrary places and there may also be other cases. A solution could be to not dispose the timer on the unhandled exception path.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions