public void RecordConnectionFailed(ConnectionFailureType failureType, Exception innerException = null, [CallerMemberName] string origin = null)
        {
            IdentifyFailureType(innerException, ref failureType);

            if (failureType == ConnectionFailureType.InternalFailure)
            {
                OnInternalError(innerException, origin);
            }

            // stop anything new coming in...
            bridge.Trace("Failed: " + failureType);
            bool isCurrent;

            PhysicalBridge.State oldState;
            bridge.OnDisconnected(failureType, this, out isCurrent, out oldState);

            if (isCurrent && Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
            {
                int now = Environment.TickCount, lastRead = Thread.VolatileRead(ref lastReadTickCount), lastWrite = Thread.VolatileRead(ref lastWriteTickCount),
                    lastBeat       = Thread.VolatileRead(ref lastBeatTickCount);
                int unansweredRead = Thread.VolatileRead(ref firstUnansweredWriteTickCount);

                string message = failureType + " on " + Format.ToString(bridge.ServerEndPoint.EndPoint) + "/" + connectionType
                                 + ", origin: " + origin
                                 + ", input-buffer: " + ioBufferBytes + ", outstanding: " + GetSentAwaitingResponseCount()
                                 + ", last-read: " + unchecked (now - lastRead) / 1000 + "s ago, last-write: " + unchecked (now - lastWrite) / 1000 + "s ago"
                                 + ", unanswered-write: " + unchecked (now - unansweredRead) / 1000 + "s ago"
                                 + ", keep-alive: " + bridge.ServerEndPoint.WriteEverySeconds + "s, pending: "
                                 + bridge.GetPendingCount() + ", state: " + oldState + ", last-heartbeat: " + (lastBeat == 0 ? "never" : (unchecked (now - lastBeat) / 1000 + "s ago"))
                                 + (bridge.IsBeating ? " (mid-beat)" : "") + ", last-mbeat: " + multiplexer.LastHeartbeatSecondsAgo + "s ago, global: "
                                 + ConnectionMultiplexer.LastGlobalHeartbeatSecondsAgo + "s ago";

                var ex = innerException == null
                    ? new RedisConnectionException(failureType, message)
                    : new RedisConnectionException(failureType, message, innerException);

                bridge.OnConnectionFailed(this, failureType, ex);
            }

            // cleanup
            lock (outstanding)
            {
                bridge.Trace(outstanding.Count != 0, "Failing outstanding messages: " + outstanding.Count);
                while (outstanding.Count != 0)
                {
                    var next = outstanding.Dequeue();
                    bridge.Trace("Failing: " + next);
                    next.Fail(failureType, innerException);
                    bridge.CompleteSyncOrAsync(next);
                }
            }

            // burn the socket
            var socketManager = multiplexer.SocketManager;

            if (socketManager != null)
            {
                socketManager.Shutdown(socketToken);
            }
        }
Exemple #2
0
        internal void OnDisconnected(ConnectionFailureType failureType, PhysicalConnection connection, out bool isCurrent, out State oldState)
        {
            Trace("OnDisconnected");

            // if the next thing in the pipe is a PING, we can tell it that we failed (this really helps spot doomed connects)
            var ping = queue.DequeueUnsentPing(out int count);

            if (ping != null)
            {
                Trace("Marking PING as failed (queue length: " + count + ")");
                ping.Fail(failureType, null);
                CompleteSyncOrAsync(ping);
            }
            oldState = default(State); // only defined when isCurrent = true
            if (isCurrent = (physical == connection))
            {
                Trace("Bridge noting disconnect from active connection" + (isDisposed ? " (disposed)" : ""));
                oldState = ChangeState(State.Disconnected);
                physical = null;

                if (!isDisposed && Interlocked.Increment(ref failConnectCount) == 1)
                {
                    GetConnection(null); // try to connect immediately
                }
            }
            else if (physical == null)
            {
                Trace("Bridge noting disconnect (already terminated)");
            }
            else
            {
                Trace("Bridge noting disconnect, but from different connection");
            }
        }
Exemple #3
0
 internal static void IdentifyFailureType(Exception exception, ref ConnectionFailureType failureType)
 {
     if (exception != null && failureType == ConnectionFailureType.InternalFailure)
     {
         if (exception is AggregateException)
         {
             exception = exception.InnerException ?? exception;
         }
         if (exception is AuthenticationException)
         {
             failureType = ConnectionFailureType.AuthenticationFailure;
         }
         else if (exception is SocketException || exception is IOException)
         {
             failureType = ConnectionFailureType.SocketFailure;
         }
         else if (exception is EndOfStreamException)
         {
             failureType = ConnectionFailureType.SocketClosed;
         }
         else if (exception is ObjectDisposedException)
         {
             failureType = ConnectionFailureType.SocketClosed;
         }
     }
 }
Exemple #4
0
        internal void OnDisconnected(ConnectionFailureType failureType, PhysicalConnection connection, out bool isCurrent, out State oldState)
        {
            Trace($"OnDisconnected: {failureType}");

            oldState = default(State); // only defined when isCurrent = true
            if (isCurrent = (physical == connection))
            {
                Trace("Bridge noting disconnect from active connection" + (isDisposed ? " (disposed)" : ""));
                oldState = ChangeState(State.Disconnected);
                physical = null;

                if (!isDisposed && Interlocked.Increment(ref failConnectCount) == 1)
                {
                    GetConnection(null); // try to connect immediately
                }
            }
            else if (physical == null)
            {
                Trace("Bridge noting disconnect (already terminated)");
            }
            else
            {
                Trace("Bridge noting disconnect, but from different connection");
            }
        }
 internal void Fail(ConnectionFailureType failure, Exception innerException)
 {
     PhysicalConnection.IdentifyFailureType(innerException, ref failure);
     if (resultProcessor != null)
     {
         resultProcessor.ConnectionFail(this, failure, innerException);
     }
 }
 internal ConnectionFailedEventArgs(EventHandler<ConnectionFailedEventArgs> handler, object sender, EndPoint endPoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception)
 {
     this.handler = handler;
     this.sender = sender;
     this.endpoint = endPoint;
     this.connectionType = connectionType;
     this.exception = exception;
     this.failureType = failureType;
 }
 internal ConnectionFailedEventArgs(EventHandler <ConnectionFailedEventArgs> handler, object sender, EndPoint endPoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception)
 {
     this.handler        = handler;
     this.sender         = sender;
     this.endpoint       = endPoint;
     this.connectionType = connectionType;
     this.exception      = exception;
     this.failureType    = failureType;
 }
 internal void OnConnectionFailed(PhysicalConnection connection, ConnectionFailureType failureType, Exception innerException)
 {
     if (reportNextFailure)
     {
         reportNextFailure = false; // until it is restored
         var endpoint = serverEndPoint.EndPoint;
         multiplexer.OnConnectionFailed(endpoint, connectionType, failureType, innerException, reconfigureNextFailure);
     }
 }
        public void ConnectionFail(Message message, ConnectionFailureType fail, Exception innerException)
        {
            PhysicalConnection.IdentifyFailureType(innerException, ref fail);

            string exMessage = fail.ToString() + (message == null ? "" : (" on " + message.Command));
            var    ex        = innerException == null ? new RedisConnectionException(fail, exMessage)
                : new RedisConnectionException(fail, exMessage, innerException);

            SetException(message, ex);
        }
Exemple #10
0
 internal ConnectionFailedEventArgs(EventHandler <ConnectionFailedEventArgs> handler, object sender, EndPoint endPoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception, string physicalName)
 {
     this.handler   = handler;
     this.sender    = sender;
     EndPoint       = endPoint;
     ConnectionType = connectionType;
     Exception      = exception;
     FailureType    = failureType;
     _physicalName  = physicalName ?? GetType().Name;
 }
Exemple #11
0
        internal static Exception ConnectionFailure(bool includeDetail, ConnectionFailureType failureType, string message, ServerEndPoint server)
        {
            var ex = new RedisConnectionException(failureType, message);

            if (includeDetail)
            {
                AddExceptionDetail(ex, null, server, null);
            }
            return(ex);
        }
Exemple #12
0
 internal void OnConnectionFailed(PhysicalConnection connection, ConnectionFailureType failureType, Exception innerException)
 {
     Trace($"OnConnectionFailed: {connection}");
     AbandonPendingBacklog(innerException);
     if (reportNextFailure)
     {
         LastException     = innerException;
         reportNextFailure = false; // until it is restored
         var endpoint = ServerEndPoint.EndPoint;
         Multiplexer.OnConnectionFailed(endpoint, ConnectionType, failureType, innerException, reconfigureNextFailure, connection?.ToString());
     }
 }
Exemple #13
0
        public void MessageFail(bool includeDetail, ConnectionFailureType failType, string messageStart)
        {
            using var muxer = Create(shared: false);
            muxer.RawConfig.IncludeDetailInExceptions = includeDetail;

            var message = Message.Create(0, CommandFlags.None, RedisCommand.GET, (RedisKey)"myKey");
            var resultBox = SimpleResultBox<string>.Create();
            message.SetSource(ResultProcessor.String, resultBox);

            message.Fail(failType, null, "my annotation", muxer as ConnectionMultiplexer);

            resultBox.GetResult(out var ex);
            Assert.NotNull(ex);

            Assert.StartsWith(messageStart, ex.Message);
        }
        public void RecordConnectionFailed(ConnectionFailureType failureType, Exception innerException = null, [CallerMemberName] string origin = null)
        {
            IdentifyFailureType(innerException, ref failureType);

            if (failureType == ConnectionFailureType.InternalFailure)
            {
                OnInternalError(innerException, origin);
            }

            // stop anything new coming in...
            bridge.Trace("Failed: " + failureType);
            bool isCurrent;

            PhysicalBridge.State oldState;
            bridge.OnDisconnected(failureType, this, out isCurrent, out oldState);

            if (isCurrent && Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
            {
                int now = Environment.TickCount, lastRead = Thread.VolatileRead(ref lastReadTickCount), lastWrite = Thread.VolatileRead(ref lastWriteTickCount),
                    lastBeat       = Thread.VolatileRead(ref lastBeatTickCount);
                int unansweredRead = Thread.VolatileRead(ref firstUnansweredWriteTickCount);

                var exMessage = new StringBuilder(failureType + " on " + Format.ToString(bridge.ServerEndPoint.EndPoint) + "/" + connectionType);
                var data      = new List <Tuple <string, string> >
                {
                    Tuple.Create("FailureType", failureType.ToString()),
                    Tuple.Create("EndPoint", Format.ToString(bridge.ServerEndPoint.EndPoint))
                };
                Action <string, string, string> add = (lk, sk, v) =>
                {
                    data.Add(Tuple.Create(lk, v));
                    exMessage.Append(", " + sk + ": " + v);
                };

                add("Origin", "origin", origin);
                add("Input-Buffer", "input-buffer", ioBufferBytes.ToString());
                add("Outstanding-Responses", "outstanding", GetSentAwaitingResponseCount().ToString());
                add("Last-Read", "last-read", unchecked (now - lastRead) / 1000 + "s ago");
                add("Last-Write", "last-write", unchecked (now - lastWrite) / 1000 + "s ago");
                add("Unanswered-Write", "unanswered-write", unchecked (now - unansweredRead) / 1000 + "s ago");
                add("Keep-Alive", "keep-alive", bridge.ServerEndPoint.WriteEverySeconds + "s");
                add("Pending", "pending", bridge.GetPendingCount().ToString());
                add("Previous-Physical-State", "state", oldState.ToString());
                add("Last-Heartbeat", "last-heartbeat", (lastBeat == 0 ? "never" : (unchecked (now - lastBeat) / 1000 + "s ago")) + (bridge.IsBeating ? " (mid-beat)" : ""));
                add("Last-Multiplexer-Heartbeat", "last-mbeat", multiplexer.LastHeartbeatSecondsAgo + "s ago");
                add("Last-Global-Heartbeat", "global", ConnectionMultiplexer.LastGlobalHeartbeatSecondsAgo + "s ago");
#if !__MonoCS__
                add("SocketManager-State", "mgr", bridge.Multiplexer.SocketManager.State.ToString());
#endif

                var ex = innerException == null
                    ? new RedisConnectionException(failureType, exMessage.ToString())
                    : new RedisConnectionException(failureType, exMessage.ToString(), innerException);

                foreach (var kv in data)
                {
                    ex.Data["Redis-" + kv.Item1] = kv.Item2;
                }

                bridge.OnConnectionFailed(this, failureType, ex);
            }

            // cleanup
            lock (outstanding)
            {
                bridge.Trace(outstanding.Count != 0, "Failing outstanding messages: " + outstanding.Count);
                while (outstanding.Count != 0)
                {
                    var next = outstanding.Dequeue();
                    bridge.Trace("Failing: " + next);
                    next.Fail(failureType, innerException);
                    bridge.CompleteSyncOrAsync(next);
                }
            }

            // burn the socket
            var socketManager = multiplexer.SocketManager;
            if (socketManager != null)
            {
                socketManager.Shutdown(socketToken);
            }
        }
 internal RedisConnectionException(ConnectionFailureType failureType, string message, Exception innerException) : base(message, innerException)
 {
     FailureType = failureType;
 }
 public void RecordConnectionFailed(ConnectionFailureType failureType, Exception innerException = null, [CallerMemberName] string origin = null)
 {
     SocketManager.ManagerState mgrState = SocketManager.ManagerState.CheckForStaleConnections;
     RecordConnectionFailed(failureType, ref mgrState, innerException, origin);
 }
 internal RedisConnectionException(ConnectionFailureType failureType, string message) : base(message)
 {
     this.FailureType = failureType;
 }
 /// <summary>
 /// This constructor is only for testing purposes.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="endPoint">Redis endpoint.</param>
 /// <param name="connectionType">Redis connection type.</param>
 /// <param name="failureType">Redis connection failure type.</param>
 /// <param name="exception">The exception that occurred.</param>
 /// <param name="physicalName">Connection physical name.</param>
 public ConnectionFailedEventArgs(object sender, EndPoint endPoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception, string physicalName)
     : this(null, sender, endPoint, connectionType, failureType, exception, physicalName)
 {
 }
        internal void OnDisconnected(ConnectionFailureType failureType, PhysicalConnection connection, out bool isCurrent, out State oldState)
        {
            Trace("OnDisconnected");

            // if the next thing in the pipe is a PING, we can tell it that we failed (this really helps spot doomed connects)
            // note that for simplicity we haven't removed it from the queue; that's OK
            int count;
            var ping = queue.PeekPing(out count);
            if (ping != null)
            {
                Trace("Marking PING as failed (queue length: " + count + ")");
                ping.Fail(failureType, null);
                CompleteSyncOrAsync(ping);
            }
            oldState = default(State); // only defined when isCurrent = true
            if (isCurrent = (physical == connection))
            {
                Trace("Bridge noting disconnect from active connection" + (isDisposed ? " (disposed)" : ""));
                oldState = ChangeState(State.Disconnected);
                physical = null;

                if (!isDisposed && Interlocked.Increment(ref failConnectCount) == 1)
                {
                    GetConnection(null); // try to connect immediately
                }
            }
            else if (physical == null)
            {
                Trace("Bridge noting disconnect (already terminated)");
            }
            else
            {
                Trace("Bridge noting disconnect, but from different connection");
            }
        }
Exemple #20
0
        public void RecordConnectionFailed(ConnectionFailureType failureType, ref SocketManager.ManagerState managerState, Exception innerException = null, [CallerMemberName] string origin = null)
        {
            IdentifyFailureType(innerException, ref failureType);

            managerState = SocketManager.ManagerState.RecordConnectionFailed_OnInternalError;
            if (failureType == ConnectionFailureType.InternalFailure)
            {
                OnInternalError(innerException, origin);
            }

            // stop anything new coming in...
            Bridge.Trace("Failed: " + failureType);
            bool isCurrent;

            PhysicalBridge.State oldState;
            int @in = -1, ar = -1;

            managerState = SocketManager.ManagerState.RecordConnectionFailed_OnDisconnected;
            Bridge.OnDisconnected(failureType, this, out isCurrent, out oldState);
            if (oldState == PhysicalBridge.State.ConnectedEstablished)
            {
                try
                {
                    @in = GetAvailableInboundBytes(out ar);
                }
                catch { /* best effort only */ }
            }

            if (isCurrent && Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
            {
                managerState = SocketManager.ManagerState.RecordConnectionFailed_ReportFailure;
                int now = Environment.TickCount, lastRead = VolatileWrapper.Read(ref lastReadTickCount), lastWrite = VolatileWrapper.Read(ref lastWriteTickCount),
                    lastBeat       = VolatileWrapper.Read(ref lastBeatTickCount);
                int unansweredRead = VolatileWrapper.Read(ref firstUnansweredWriteTickCount);

                var exMessage = new StringBuilder(failureType + " on " + Format.ToString(Bridge.ServerEndPoint.EndPoint) + "/" + connectionType);
                var data      = new List <Tuple <string, string> >
                {
                    Tuple.Create("FailureType", failureType.ToString()),
                    Tuple.Create("EndPoint", Format.ToString(Bridge.ServerEndPoint.EndPoint))
                };
                Action <string, string, string> add = (lk, sk, v) =>
                {
                    data.Add(Tuple.Create(lk, v));
                    exMessage.Append(", " + sk + ": " + v);
                };

                add("Origin", "origin", origin);
                add("Input-Buffer", "input-buffer", ioBufferBytes.ToString());
                add("Outstanding-Responses", "outstanding", GetSentAwaitingResponseCount().ToString());
                add("Last-Read", "last-read", unchecked (now - lastRead) / 1000 + "s ago");
                add("Last-Write", "last-write", unchecked (now - lastWrite) / 1000 + "s ago");
                add("Unanswered-Write", "unanswered-write", unchecked (now - unansweredRead) / 1000 + "s ago");
                add("Keep-Alive", "keep-alive", Bridge.ServerEndPoint.WriteEverySeconds + "s");
                add("Pending", "pending", Bridge.GetPendingCount().ToString());
                add("Previous-Physical-State", "state", oldState.ToString());

                if (@in >= 0)
                {
                    add("Inbound-Bytes", "in", @in.ToString());
                    add("Active-Readers", "ar", ar.ToString());
                }

                add("Last-Heartbeat", "last-heartbeat", (lastBeat == 0 ? "never" : (unchecked (now - lastBeat) / 1000 + "s ago")) + (Bridge.IsBeating ? " (mid-beat)" : ""));
                add("Last-Multiplexer-Heartbeat", "last-mbeat", Multiplexer.LastHeartbeatSecondsAgo + "s ago");
                add("Last-Global-Heartbeat", "global", ConnectionMultiplexer.LastGlobalHeartbeatSecondsAgo + "s ago");
#if FEATURE_SOCKET_MODE_POLL
                var mgr = Bridge.Multiplexer.SocketManager;
                add("SocketManager-State", "mgr", mgr.State.ToString());
                add("Last-Error", "err", mgr.LastErrorTimeRelative());
#endif

                var ex = innerException == null
                    ? new RedisConnectionException(failureType, exMessage.ToString())
                    : new RedisConnectionException(failureType, exMessage.ToString(), innerException);

                foreach (var kv in data)
                {
                    ex.Data["Redis-" + kv.Item1] = kv.Item2;
                }

                managerState = SocketManager.ManagerState.RecordConnectionFailed_OnConnectionFailed;
                Bridge.OnConnectionFailed(this, failureType, ex);
            }

            // cleanup
            managerState = SocketManager.ManagerState.RecordConnectionFailed_FailOutstanding;
            lock (outstanding)
            {
                Bridge.Trace(outstanding.Count != 0, "Failing outstanding messages: " + outstanding.Count);
                while (outstanding.Count != 0)
                {
                    var next = outstanding.Dequeue();
                    Bridge.Trace("Failing: " + next);
                    next.Fail(failureType, innerException);
                    Bridge.CompleteSyncOrAsync(next);
                }
            }

            // burn the socket
            managerState = SocketManager.ManagerState.RecordConnectionFailed_ShutdownSocket;
            Multiplexer.SocketManager?.Shutdown(socketToken);
        }
Exemple #21
0
 public void RecordConnectionFailed(ConnectionFailureType failureType, Exception innerException = null, [CallerMemberName] string origin = null)
 {
     SocketManager.ManagerState mgrState = SocketManager.ManagerState.CheckForStaleConnections;
     RecordConnectionFailed(failureType, ref mgrState, innerException, origin);
 }
Exemple #22
0
 /// <summary>
 /// Creates a new <see cref="RedisConnectionException"/>.
 /// </summary>
 /// <param name="failureType">The type of connection failure.</param>
 /// <param name="message">The message for the exception.</param>
 /// <param name="innerException">The inner exception.</param>
 public RedisConnectionException(ConnectionFailureType failureType, string message, Exception innerException) : this(failureType, message, innerException, CommandStatus.Unknown)
 {
 }
 internal static void IdentifyFailureType(Exception exception, ref ConnectionFailureType failureType)
 {
     if (exception != null && failureType == ConnectionFailureType.InternalFailure)
     {
         if (exception is AuthenticationException) failureType = ConnectionFailureType.AuthenticationFailure;
         else if (exception is SocketException || exception is IOException) failureType = ConnectionFailureType.SocketFailure;
         else if (exception is EndOfStreamException) failureType = ConnectionFailureType.SocketClosed;
         else if (exception is ObjectDisposedException) failureType = ConnectionFailureType.SocketClosed;
     }
 }
        public void RecordConnectionFailed(ConnectionFailureType failureType, Exception innerException = null, [CallerMemberName] string origin = null)
        {
            IdentifyFailureType(innerException, ref failureType);

            if (failureType == ConnectionFailureType.InternalFailure) OnInternalError(innerException, origin);

            // stop anything new coming in...
            bridge.Trace("Failed: " + failureType);
            bool isCurrent;
            PhysicalBridge.State oldState;
            int @in = -1, ar = -1;
            bridge.OnDisconnected(failureType, this, out isCurrent, out oldState);
            if(oldState == PhysicalBridge.State.ConnectedEstablished)
            {
                try
                {
                    @in = GetAvailableInboundBytes(out ar);
                }
                catch { /* best effort only */ }
            }

            if (isCurrent && Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
            {
                int now = Environment.TickCount, lastRead = Thread.VolatileRead(ref lastReadTickCount), lastWrite = Thread.VolatileRead(ref lastWriteTickCount),
                    lastBeat = Thread.VolatileRead(ref lastBeatTickCount);
                int unansweredRead = Thread.VolatileRead(ref firstUnansweredWriteTickCount);

                var exMessage = new StringBuilder(failureType + " on " + Format.ToString(bridge.ServerEndPoint.EndPoint) + "/" + connectionType);
                var data = new List<Tuple<string, string>>
                {
                    Tuple.Create("FailureType", failureType.ToString()),
                    Tuple.Create("EndPoint", Format.ToString(bridge.ServerEndPoint.EndPoint))
                };
                Action<string, string, string> add = (lk, sk, v) =>
                {
                    data.Add(Tuple.Create(lk, v));
                    exMessage.Append(", " + sk + ": " + v);
                };

                add("Origin", "origin", origin);
                add("Input-Buffer", "input-buffer", ioBufferBytes.ToString());
                add("Outstanding-Responses", "outstanding", GetSentAwaitingResponseCount().ToString());
                add("Last-Read", "last-read", unchecked(now - lastRead) / 1000 + "s ago");
                add("Last-Write", "last-write", unchecked(now - lastWrite) / 1000 + "s ago");
                add("Unanswered-Write", "unanswered-write", unchecked(now - unansweredRead) / 1000 + "s ago");
                add("Keep-Alive", "keep-alive", bridge.ServerEndPoint.WriteEverySeconds + "s");
                add("Pending", "pending", bridge.GetPendingCount().ToString());
                add("Previous-Physical-State", "state", oldState.ToString());

                if(@in >= 0)
                {
                    add("Inbound-Bytes", "in", @in.ToString());
                    add("Active-Readers", "ar", ar.ToString());
                }

                add("Last-Heartbeat", "last-heartbeat", (lastBeat == 0 ? "never" : (unchecked(now - lastBeat)/1000 + "s ago"))+ (bridge.IsBeating ? " (mid-beat)" : "") );
                add("Last-Multiplexer-Heartbeat", "last-mbeat", multiplexer.LastHeartbeatSecondsAgo + "s ago");
                add("Last-Global-Heartbeat", "global", ConnectionMultiplexer.LastGlobalHeartbeatSecondsAgo + "s ago");
#if !__MonoCS__
                var mgr = bridge.Multiplexer.SocketManager;
                add("SocketManager-State", "mgr", mgr.State.ToString());
                add("Last-Error", "err", mgr.LastErrorTimeRelative());
#endif
                
                var ex = innerException == null
                    ? new RedisConnectionException(failureType, exMessage.ToString())
                    : new RedisConnectionException(failureType, exMessage.ToString(), innerException);

                foreach (var kv in data)
                {
                    ex.Data["Redis-" + kv.Item1] = kv.Item2;
                }

                bridge.OnConnectionFailed(this, failureType, ex);
            }

            // cleanup
            lock (outstanding)
            {
                bridge.Trace(outstanding.Count != 0, "Failing outstanding messages: " + outstanding.Count);
                while (outstanding.Count != 0)
                {
                    var next = outstanding.Dequeue();
                    bridge.Trace("Failing: " + next);
                    next.Fail(failureType, innerException);
                    bridge.CompleteSyncOrAsync(next);
                }
            }

            // burn the socket
            var socketManager = multiplexer.SocketManager;
            if (socketManager != null) socketManager.Shutdown(socketToken);
        }
 public void ConnectionFail(Message message, ConnectionFailureType fail, string errorMessage)
 {
     SetException(message, new RedisConnectionException(fail, errorMessage));
 }
Exemple #26
0
    internal void OnConnectionFailed(EndPoint endpoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception, bool reconfigure, string physicalName)
    {
        if (_isDisposed)
        {
            return;
        }
        var handler = ConnectionFailed;

        if (handler != null)
        {
            CompleteAsWorker(new ConnectionFailedEventArgs(handler, this, endpoint, connectionType, failureType, exception, physicalName));
        }
        if (reconfigure)
        {
            ReconfigureIfNeeded(endpoint, false, "connection failed");
        }
    }
 internal void OnConnectionFailed(PhysicalConnection connection, ConnectionFailureType failureType, Exception innerException)
 {
     if (reportNextFailure)
     {
         reportNextFailure = false; // until it is restored
         var endpoint = serverEndPoint.EndPoint;
         multiplexer.OnConnectionFailed(endpoint, connectionType, failureType, innerException, reconfigureNextFailure);
     }
 }
 internal static Exception ConnectionFailure(bool includeDetail, ConnectionFailureType failureType, string message, ServerEndPoint server)
 {
     var ex = new RedisConnectionException(failureType, message);
     if (includeDetail) AddDetail(ex, null, server, null);
     return ex;
 }
Exemple #29
0
 /// <summary>
 /// Creates a new <see cref="RedisConnectionException"/>.
 /// </summary>
 /// <param name="failureType">The type of connection failure.</param>
 /// <param name="message">The message for the exception.</param>
 /// <param name="innerException">The inner exception.</param>
 /// <param name="commandStatus">The status of the command.</param>
 public RedisConnectionException(ConnectionFailureType failureType, string message, Exception innerException, CommandStatus commandStatus) : base(message, innerException)
 {
     FailureType   = failureType;
     CommandStatus = commandStatus;
 }
        public void RecordConnectionFailed(ConnectionFailureType failureType, Exception innerException = null, [CallerMemberName] string origin = null)
        {
            IdentifyFailureType(innerException, ref failureType);

            if (failureType == ConnectionFailureType.InternalFailure) OnInternalError(innerException, origin);

            // stop anything new coming in...
            bridge.Trace("Failed: " + failureType);
            bool isCurrent;
            PhysicalBridge.State oldState;
            bridge.OnDisconnected(failureType, this, out isCurrent, out oldState);

            if (isCurrent && Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
            {
                //try
                //{
                long now = Environment.TickCount, lastRead = Interlocked.Read(ref lastReadTickCount), lastWrite = Interlocked.Read(ref lastWriteTickCount),
                    lastBeat = Interlocked.Read(ref lastBeatTickCount);

                string message = failureType + " on " + Format.ToString(bridge.ServerEndPoint.EndPoint) + "/" + connectionType
                    + ", input-buffer: " + ioBufferBytes + ", outstanding: " + GetSentAwaitingResponseCount()
                    + ", last-read: " + unchecked(now - lastRead) / 1000 + "s ago, last-write: " + unchecked(now - lastWrite) / 1000 + "s ago, keep-alive: " + bridge.ServerEndPoint.WriteEverySeconds + "s, pending: "
                    + bridge.GetPendingCount() + ", state: " + oldState + ", last-heartbeat: " + (lastBeat == 0 ? "never" : (unchecked(now - lastBeat) / 1000 + "s ago"))
                    + (bridge.IsBeating ? " (mid-beat)" : "") + ", last-mbeat: " + multiplexer.LastHeartbeatSecondsAgo + "s ago, global: "
                    + ConnectionMultiplexer.LastGlobalHeartbeatSecondsAgo + "s ago";

                var ex = innerException == null
                    ? new RedisConnectionException(failureType, message)
                    : new RedisConnectionException(failureType, message, innerException);

                bridge.OnConnectionFailed(this, failureType, ex);
                //    throw ex;
                //}
                //catch (Exception caught)
                //{
                //    bridge.OnConnectionFailed(this, failureType, caught);
                //}

            }

            // cleanup
            lock (outstanding)
            {
                bridge.Trace(outstanding.Count != 0, "Failing outstanding messages: " + outstanding.Count);
                while (outstanding.Count != 0)
                {
                    var next = outstanding.Dequeue();
                    bridge.Trace("Failing: " + next);
                    next.Fail(failureType, innerException);
                    bridge.CompleteSyncOrAsync(next);
                }
            }

            // burn the socket
            var socketManager = multiplexer.SocketManager;
            if (socketManager != null) socketManager.Shutdown(socketToken);
        }