OnPhysicalLogHandleClose(PhysicalLog.Handle ToClose, CancellationToken cancellationToken) { await _Lock.WaitUntilSetAsync(cancellationToken).ConfigureAwait(false); try { PhysicalLog handleOwner = null; ReleaseAssert.AssertIfNot(_Logs.TryGetValue(ToClose.OwnerId, out handleOwner), "_Logs index is inconsistent"); if (await handleOwner.OnCloseHandle(ToClose, cancellationToken).ConfigureAwait(false)) { // last reference on the PhysicalLog removed - it is closed, remove from this _Logs index _Logs.Remove(ToClose.OwnerId); if ((_Handles.Count == 0) && (_Logs.Count == 0)) { var m = _AppDomainPhysLogManager; _AppDomainPhysLogManager = null; try { await m.CloseAsync(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { // // Close can throw STATUS_OBJECT_NO_LONGER_EXISTS if the log has been deleted while // the opened. This is benign and so just ignore it. // // TODO asnegi: RDBug #10278280 Adding 0xc0190021 as it is expected HResult for exception. However, it seems that it is not being // translated to 0x80071A97 or generated properly in dotnet_coreclr_linux. if ((ex.InnerException == null) || ((ex.InnerException.HResult != unchecked ((int)0x80071A97)) && (ex.InnerException.HResult != unchecked ((int)0xc0190021))) || (ex.InnerException.InnerException != null && ex.InnerException.InnerException.HResult != unchecked ((int)0xc0190021))) { // Only ERROR_OBJECT_NO_LONGER_EXISTS is an expected result code. Any other error should be passed back up throw; } } } } } finally { _Lock.Set(); } }