public void Dispose()
        {
            _runTransactions = false;

            // once all the concurrent transactions are done, this will signal the event, preventing
            // it from adding additional operations
            var done = _concurrentOperations.Signal();

            _waitHandle.Set();
            _txLongRunningOperation?.Join(int.MaxValue);
            _waitHandle.Dispose();

            // make sure that the queue is empty and there are no pending
            // transactions waiting.
            // this is probably a bit more aggresive that what is needed, but it is better
            // to be cautious and slower on rare dispose than hang

            while (done == false)
            {
                try
                {
                    done = _concurrentOperations.Signal();
                }
                catch (InvalidOperationException)
                {
                    break;
                }
            }

            while (_operations.TryDequeue(out MergedTransactionCommand result))
            {
                result.TaskCompletionSource.TrySetCanceled();
            }
        }
        public void Dispose()
        {
            _cts.Cancel();
            _tcp.Dispose();

            try
            {
                if (_collectingTask == null)
                {
                    return;
                }

                if (_collectingTask.ManagedThreadId == Thread.CurrentThread.ManagedThreadId)
                {
                    return;
                }

                if (_collectingTask.Join((int)TimeSpan.FromSeconds(30).TotalMilliseconds) == false)
                {
                    throw new ObjectDisposedException($"{_name} still running and can't be closed");
                }
            }
            finally
            {
                _cts.Dispose();
            }
        }
Exemple #3
0
        public void Dispose()
        {
            _connection.Dispose();
            if (_engine.Log.IsInfoEnabled)
            {
                _engine.Log.Info($"{ToString()}: Disposing");
            }

            if (_followerLongRunningWork != null && _followerLongRunningWork.ManagedThreadId != Thread.CurrentThread.ManagedThreadId)
            {
                _followerLongRunningWork.Join(int.MaxValue);
            }

            _engine.InMemoryDebug.RemoveRecorderOlderThan(DateTime.UtcNow.AddMinutes(-5));
        }
Exemple #4
0
        public void Dispose()
        {
            _connection.Dispose();
            if (_engine.Log.IsInfoEnabled)
            {
                _engine.Log.Info($"{ToString()}: Disposing");
            }

            if (_followerLongRunningWork != null && _followerLongRunningWork.ManagedThreadId != Thread.CurrentThread.ManagedThreadId)
            {
                _followerLongRunningWork.Join(int.MaxValue);
            }

            _engine.InMemoryDebug.RemoveRecorder(_debugName);
        }
Exemple #5
0
        public void Dispose()
        {
            if (_electionWon == false)
            {
                _connection.Dispose();
            }

            if (_engine.Log.IsInfoEnabled)
            {
                _engine.Log.Info($"{ToString()}: Disposing");
            }

            if (_electorLongRunningWork != null && _electorLongRunningWork.ManagedThreadId != Thread.CurrentThread.ManagedThreadId)
            {
                _electorLongRunningWork.Join(int.MaxValue);
            }
        }
Exemple #6
0
        public void Dispose()
        {
            // There are multiple invocations of dispose, this happens sometimes during tests, causing failures.
            if (!_disposed.Raise())
            {
                return;
            }

            var timeout = _parent._server.Engine.TcpConnectionTimeout;

            if (_log.IsInfoEnabled)
            {
                _log.Info($"Disposing OutgoingReplicationHandler ({FromToString}) [Timeout:{timeout}]");
            }

            _database.Changes.OnDocumentChange -= OnDocumentChange;
            _database.Changes.OnCounterChange  -= OnCounterChange;

            _cts.Cancel();

            DisposeTcpClient();

            _connectionDisposed.Set();

            if (_longRunningSendingWork != null && _longRunningSendingWork != PoolOfThreads.LongRunningWork.Current)
            {
                while (_longRunningSendingWork.Join((int)timeout.TotalMilliseconds) == false)
                {
                    if (_log.IsInfoEnabled)
                    {
                        _log.Info($"Waited {timeout} for timeout to occur, but still this thread is keep on running. Will wait another {timeout} ");
                    }
                    DisposeTcpClient();
                }
            }

            try
            {
                _cts.Dispose();
            }
            catch (ObjectDisposedException)
            {
                //was already disposed? we don't care, we are disposing
            }
        }
Exemple #7
0
        public void Dispose()
        {
            // We lost the election, if we disposing the candidate without winning
            if (ElectionResult != ElectionResult.Won)
            {
                ElectionResult = ElectionResult.Lost;
            }
            _running.Lower();
            _stateChange.TrySetResult(null);
            _peersWaiting.Set();
            if (_engine.Log.IsInfoEnabled)
            {
                _engine.Log.Info($"Candidate {_engine.Tag}: Dispose");
            }

            if (_longRunningWork != null && _longRunningWork != PoolOfThreads.LongRunningWork.Current)
            {
                _longRunningWork.Join(Int32.MaxValue);
            }
        }