Fix deadlock in RemoteCollectorStorageManager by releasing lock during callback execution

BEGIN_PUBLIC
Fix deadlock in RemoteCollectorStorageManager by releasing lock during callback execution.
END_PUBLIC

Invoking EventStorageManager::EventHandler::OnEvent callback while holding the internal mutex causes deadlocks if the callback re-enters the storage manager (e.g. calling ResetEventHandler on error paths).

To fix this, refactored RemoteCollectorStorageManager to obtain a pointer to the handler, release the lock, and invoke OnEvent safely outside the locked scope. Added active callback thread tracking in EventStorageManager to block ResetEventHandler and Reset calls until all concurrent callbacks have finished executing. Bypassed the block if the re-entrant call is made on the same thread to prevent self-deadlock.

Verified by running new and existing unit tests:
- RemoteCollectorStorageManagerTest.ReentrantResetEventHandlerDoesNotDeadlock
- //third_party/milotic/internal/cc/proxy/sse_plugin:collector_storage_manager_test
- //third_party/milotic/internal/cc/proxy/sse_plugin:storage_manager_test
- //third_party/milotic/internal/cc/proxy/cper:manager_test

PiperOrigin-RevId: 936976417
Change-Id: I69e1c54e7190ae102181c7121f1cf6227df9e27b
3 files changed