Пример #1
0
        OnLogicalLogClose(LogicalLog 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.OnCloseLogicalLog(ToClose, cancellationToken).ConfigureAwait(false))
                {
                    // last handle or logical log closed on the PhysicalLog, removed from this index
                    _Logs.Remove(ToClose.OwnerId);
                    if ((_Handles.Count == 0) && (_Logs.Count == 0))
                    {
                        var m = _AppDomainPhysLogManager;
                        _AppDomainPhysLogManager = null;
                        await m.CloseAsync(cancellationToken).ConfigureAwait(false);
                    }
                }
            }
            finally
            {
                _Lock.Set();
            }
        }
Пример #2
0
        OnCloseHandle(Handle toClose, CancellationToken cancellationToken)
        {
            await _Lock.WaitUntilSetAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                WeakReference <Handle> wr;
                if (_Handles.TryGetValue(toClose.Id, out wr) == false)
                {
                    ReleaseAssert.Failfast("toClose missing from _Handles");
                }

                _Handles.Remove(toClose.Id);
                if ((_Handles.Count == 0) && (_Logs.Count == 0))
                {
                    // No references to this PhysicalLogManager - reverse allocation
                    var m = _AppDomainPhysLogManager;
                    _AppDomainPhysLogManager = null;

                    try
                    {
                        await m.CloseAsync(cancellationToken).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        AppTrace.TraceSource.WriteInfo(TraceType, "OnCloseHandle: Exception {0}", ex);
                    }
                }
            }
            finally
            {
                _Lock.Set();
            }
        }
Пример #3
0
        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();
            }
        }
Пример #4
0
        InternalCreateAsync(LogManager.LoggerType logManagerType, CancellationToken cancellationToken)
        {
            Handle             result          = null;
            PhysicalLogManager newManager      = null;
            Exception          caughtException = null;

            await _Lock.WaitUntilSetAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                if (_AppDomainPhysLogManager == null)
                {
                    if (logManagerType == LogManager.LoggerType.Default)
                    {
                        //
                        // Try to open driver first and if it fails then try inproc
                        //
                        try
                        {
                            newManager = new PhysicalLogManager(LogManager.LoggerType.Driver);
                            await newManager.OpenAsync(cancellationToken).ConfigureAwait(false);
                        }
                        catch (System.IO.FileNotFoundException)
                        {
                            AppTrace.TraceSource.WriteInfo(TraceType, "InternalCreateAsync: FileNotFound returned when trying to open Driver. Proceeding with an Inproc log.");

                            //
                            // Don't fail if driver isn't loaded
                            //
                            newManager = null;
                        }

                        if (newManager == null)
                        {
                            //
                            // Now try inproc
                            //
                            newManager = new PhysicalLogManager(LogManager.LoggerType.Inproc);
                            await newManager.OpenAsync(cancellationToken).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        //
                        // Only try to open a specific log manager type
                        //
                        newManager = new PhysicalLogManager(logManagerType);
                        await newManager.OpenAsync(cancellationToken).ConfigureAwait(false);
                    }

                    _LoggerType = newManager.GetLoggerType();
                    _AppDomainPhysLogManager = newManager; // No error during Open -
                }

                _NextHandleId++;
                result = new Handle(_NextHandleId);
                _Handles.Add(_NextHandleId, new WeakReference <Handle>(result, false));
                result.IsOpen = true;
                newManager    = null;
            }
            catch (Exception ex)
            {
                caughtException = ex; // for later re-throw

                if (result != null)
                {
                    // Undo handle creation
                    result.IsOpen = false;
                    _Handles.Remove(result.Id);
                }

                if (newManager != null)
                {
                    // Reverse creation of AppDomain singleton
                    _AppDomainPhysLogManager = null;
                    _LoggerType = LogManager.LoggerType.Unknown;
                }
            }
            finally
            {
                _Lock.Set();
            }

            if (caughtException != null)
            {
                if (newManager != null)
                {
                    // Finish reversal of creation of AppDomain singleton
                    await newManager.CloseAsync(cancellationToken).ConfigureAwait(false);
                }

                throw caughtException;
            }

            return(result);
        }