Skip to content

Add TimeOut to Abort call in dispose #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ TestResult.xml
/NuGet
.vscode/
*.lock.json
api/

test.sh
*.VisualState.xml
Expand Down
8 changes: 4 additions & 4 deletions projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class IConnectionExtensions
/// </remarks>
public static void Close(this IConnection connection)
{
connection.Close(Constants.ReplySuccess, "Goodbye", TimeSpan.FromSeconds(30), false);
connection.Close(Constants.ReplySuccess, "Goodbye", InternalConstants.DefaultConnectionCloseTimeout, false);
}

/// <summary>
Expand All @@ -37,7 +37,7 @@ public static void Close(this IConnection connection)
/// </remarks>
public static void Close(this IConnection connection, ushort reasonCode, string reasonText)
{
connection.Close(reasonCode, reasonText, TimeSpan.FromSeconds(30), false);
connection.Close(reasonCode, reasonText, InternalConstants.DefaultConnectionCloseTimeout, false);
}

/// <summary>
Expand Down Expand Up @@ -93,7 +93,7 @@ public static void Close(this IConnection connection, ushort reasonCode, string
/// </remarks>
public static void Abort(this IConnection connection)
{
connection.Close(Constants.ReplySuccess, "Connection close forced", TimeSpan.FromSeconds(5), true);
connection.Close(Constants.ReplySuccess, "Connection close forced", InternalConstants.DefaultConnectionAbortTimeout, true);
}

/// <summary>
Expand All @@ -111,7 +111,7 @@ public static void Abort(this IConnection connection)
/// </remarks>
public static void Abort(this IConnection connection, ushort reasonCode, string reasonText)
{
connection.Close(reasonCode, reasonText, TimeSpan.FromSeconds(5), true);
connection.Close(reasonCode, reasonText, InternalConstants.DefaultConnectionAbortTimeout, true);
}

/// <summary>
Expand Down
41 changes: 41 additions & 0 deletions projects/RabbitMQ.Client/client/api/InternalConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This source code is dual-licensed under the Apache License, version
// 2.0, and the Mozilla Public License, version 2.0.
//
// The APL v2.0:
//
//---------------------------------------------------------------------------
// Copyright (c) 2007-2020 VMware, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//---------------------------------------------------------------------------
//
// The MPL v2.0:
//
//---------------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
//---------------------------------------------------------------------------

using System;

namespace RabbitMQ.Client
{
internal static class InternalConstants
{
internal static readonly TimeSpan DefaultConnectionAbortTimeout = TimeSpan.FromSeconds(5);
internal static readonly TimeSpan DefaultConnectionCloseTimeout = TimeSpan.FromSeconds(30);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void Dispose()

try
{
this.Abort();
this.Abort(InternalConstants.DefaultConnectionAbortTimeout);
}
catch (Exception)
{
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/client/impl/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

namespace RabbitMQ.Client.Framing.Impl
{
#nullable enable
#nullable enable
internal sealed partial class Connection : IConnection
{
private bool _disposed;
Expand Down Expand Up @@ -410,7 +410,7 @@ public void Dispose()

try
{
this.Abort();
this.Abort(InternalConstants.DefaultConnectionAbortTimeout);
_mainLoopTask.Wait();
}
catch (OperationInterruptedException)
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/impl/ModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ protected void HandleConnectionStart(in IncomingCommand cmd)
if (m_connectionStartCell is null)
{
var reason = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.CommandInvalid, "Unexpected Connection.Start");
Session.Connection.Close(reason, false, TimeSpan.FromSeconds(30));
Session.Connection.Close(reason, false, InternalConstants.DefaultConnectionCloseTimeout);
}

var method = new ConnectionStart(cmd.MethodBytes.Span);
Expand Down
1 change: 1 addition & 0 deletions projects/Unit/APIApproval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
//---------------------------------------------------------------------------

using System.Reflection;
using System.Threading.Tasks;

using PublicApiGenerator;
Expand Down
32 changes: 21 additions & 11 deletions projects/Unit/Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,37 @@

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Threading;
using RabbitMQ.Client.Framing;
using System.Text;
using RabbitMQ.Client.Framing.Impl;

using Xunit;

using static RabbitMQ.Client.Unit.RabbitMQCtl;
using Xunit.Abstractions;

namespace RabbitMQ.Client.Unit
{

[Collection("IntegrationFixture")]
public class IntegrationFixture : IDisposable
{
internal IConnectionFactory _connFactory;
internal IConnection _conn;
internal IModel _model;
internal Encoding _encoding = new UTF8Encoding();

public static TimeSpan RECOVERY_INTERVAL = TimeSpan.FromSeconds(2);

protected IntegrationFixture()
protected readonly ITestOutputHelper _output;
protected readonly string _testDisplayName;

public IntegrationFixture(ITestOutputHelper output)
{
_output = output;
var type = _output.GetType();
var testMember = type.GetField("test", BindingFlags.Instance | BindingFlags.NonPublic);
var test = (ITest)testMember.GetValue(output);
_testDisplayName = test.DisplayName;

SetUp();
}

Expand All @@ -71,6 +80,7 @@ public virtual void Dispose()
{
_model.Close();
}

if (_conn.IsOpen)
{
_conn.Close();
Expand Down Expand Up @@ -105,7 +115,7 @@ internal AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan interv
AutomaticRecoveryEnabled = true,
NetworkRecoveryInterval = interval
};
return (AutorecoveringConnection)cf.CreateConnection($"UNIT_CONN:{Guid.NewGuid()}");
return (AutorecoveringConnection)cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}");
}

internal AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan interval, IList<string> hostnames)
Expand All @@ -118,7 +128,7 @@ internal AutorecoveringConnection CreateAutorecoveringConnection(TimeSpan interv
RequestedConnectionTimeout = TimeSpan.FromSeconds(1),
NetworkRecoveryInterval = interval
};
return (AutorecoveringConnection)cf.CreateConnection(hostnames, $"UNIT_CONN:{Guid.NewGuid()}");
return (AutorecoveringConnection)cf.CreateConnection(hostnames, $"{_testDisplayName}:{Guid.NewGuid()}");
}

internal AutorecoveringConnection CreateAutorecoveringConnection(IList<AmqpTcpEndpoint> endpoints)
Expand All @@ -131,7 +141,7 @@ internal AutorecoveringConnection CreateAutorecoveringConnection(IList<AmqpTcpEn
RequestedConnectionTimeout = TimeSpan.FromSeconds(1),
NetworkRecoveryInterval = RECOVERY_INTERVAL
};
return (AutorecoveringConnection)cf.CreateConnection(endpoints, $"UNIT_CONN:{Guid.NewGuid()}");
return (AutorecoveringConnection)cf.CreateConnection(endpoints, $"{_testDisplayName}:{Guid.NewGuid()}");
}

internal AutorecoveringConnection CreateAutorecoveringConnectionWithTopologyRecoveryDisabled()
Expand All @@ -142,7 +152,7 @@ internal AutorecoveringConnection CreateAutorecoveringConnectionWithTopologyReco
TopologyRecoveryEnabled = false,
NetworkRecoveryInterval = RECOVERY_INTERVAL
};
return (AutorecoveringConnection)cf.CreateConnection($"UNIT_CONN:{Guid.NewGuid()}");
return (AutorecoveringConnection)cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}");
}

internal IConnection CreateConnectionWithContinuationTimeout(bool automaticRecoveryEnabled, TimeSpan continuationTimeout)
Expand All @@ -152,7 +162,7 @@ internal IConnection CreateConnectionWithContinuationTimeout(bool automaticRecov
AutomaticRecoveryEnabled = automaticRecoveryEnabled,
ContinuationTimeout = continuationTimeout
};
return cf.CreateConnection($"UNIT_CONN:{Guid.NewGuid()}");
return cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}");
}

//
Expand Down
1 change: 1 addition & 0 deletions projects/Unit/RabbitMQCtl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public static void RestartRabbitMQ()
StopRabbitMQ();
Thread.Sleep(500);
StartRabbitMQ();
AwaitRabbitMQ();
}

public static void StopRabbitMQ()
Expand Down
6 changes: 5 additions & 1 deletion projects/Unit/TestAsyncConsumerExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@
using RabbitMQ.Client.Events;

using Xunit;
using Xunit.Abstractions;

namespace RabbitMQ.Client.Unit
{

public class TestAsyncConsumerExceptions : IntegrationFixture
{
private static readonly Exception TestException = new Exception("oops");

public TestAsyncConsumerExceptions(ITestOutputHelper output) : base(output)
{
}

protected void TestExceptionHandlingWith(IBasicConsumer consumer,
Action<IModel, string, IBasicConsumer, string> action)
{
Expand Down
6 changes: 5 additions & 1 deletion projects/Unit/TestBasicGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@
using RabbitMQ.Client.Exceptions;

using Xunit;
using Xunit.Abstractions;

namespace RabbitMQ.Client.Unit
{

public class TestBasicGet : IntegrationFixture
{
public TestBasicGet(ITestOutputHelper output) : base(output)
{
}

[Fact]
public void TestBasicGetWithClosedChannel()
{
Expand Down
1 change: 0 additions & 1 deletion projects/Unit/TestBlockingCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

namespace RabbitMQ.Client.Unit
{

public class TestBlockingCell : TimingFixture
{
internal class DelayedSetter<T>
Expand Down
6 changes: 5 additions & 1 deletion projects/Unit/TestChannelSoftErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
using RabbitMQ.Client.Exceptions;

using Xunit;
using Xunit.Abstractions;

namespace RabbitMQ.Client.Unit
{

public class TestChannelSoftErrors : IntegrationFixture
{
public TestChannelSoftErrors(ITestOutputHelper output) : base(output)
{
}

[Fact]
public void TestBindOnNonExistingQueue()
{
Expand Down
5 changes: 5 additions & 0 deletions projects/Unit/TestConcurrentAccessWithSharedConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using System.Threading.Tasks;

using Xunit;
using Xunit.Abstractions;

namespace RabbitMQ.Client.Unit
{
Expand All @@ -45,6 +46,10 @@ public class TestConcurrentAccessWithSharedConnection : IntegrationFixture
internal CountdownEvent _latch;
internal TimeSpan _completionTimeout = TimeSpan.FromSeconds(90);

public TestConcurrentAccessWithSharedConnection(ITestOutputHelper output) : base(output)
{
}

protected override void SetUp()
{
base.SetUp();
Expand Down
5 changes: 4 additions & 1 deletion projects/Unit/TestConfirmSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
//---------------------------------------------------------------------------

using Xunit;
using Xunit.Abstractions;

namespace RabbitMQ.Client.Unit
{

public class TestConfirmSelect : IntegrationFixture
{
public TestConfirmSelect(ITestOutputHelper output) : base(output)
{
}

[Fact]
public void TestConfirmSelectIdempotency()
Expand Down
Loading