Skip to content

Commit 9b340dc

Browse files
authored
Merge branch '6.x' into fnel/6.x/fix-buffer-overflow
2 parents a437217 + 1fac6fc commit 9b340dc

17 files changed

+237
-51
lines changed

.github/workflows/main.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: rabbitmq-dotnet-client
2+
3+
on:
4+
push:
5+
branches: [ 6.x ]
6+
pull_request:
7+
branches: [ 6.x ]
8+
9+
jobs:
10+
build-win32:
11+
name: build/test on windows-latest
12+
13+
runs-on: windows-latest
14+
15+
# https://github.com/NuGet/Home/issues/11548
16+
env:
17+
NUGET_CERT_REVOCATION_MODE: offline
18+
19+
steps:
20+
- name: Clone repository
21+
uses: actions/checkout@v2
22+
with:
23+
submodules: true
24+
- name: Cache installers
25+
uses: actions/cache@v2
26+
with:
27+
# Note: the cache path is relative to the workspace directory
28+
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#using-the-cache-action
29+
path: ~/installers
30+
key: ${{ runner.os }}-v0-${{ hashFiles('tools/versions.json') }}
31+
- name: Cache NuGet packages
32+
uses: actions/cache@v2
33+
with:
34+
path: |
35+
~/.nuget/packages
36+
~/AppData/Local/NuGet/v3-cache
37+
key: ${{ runner.os }}-v0-nuget-${{ hashFiles('**/*.csproj') }}
38+
restore-keys: |
39+
${{ runner.os }}-v0-nuget-
40+
- name: Install and start RabbitMQ
41+
run: ./tools/install.ps1
42+
- name: List NuGet sources
43+
run: dotnet nuget locals all --list
44+
- name: Restore
45+
run: dotnet restore --verbosity=normal
46+
- name: ApiGen
47+
run: dotnet run --project ./projects/Apigen/Apigen.csproj --apiName:AMQP_0_9_1 ./projects/specs/amqp0-9-1.stripped.xml ./gensrc/autogenerated-api-0-9-1.cs
48+
- name: Build
49+
run: dotnet build --no-restore --verbosity=normal
50+
- name: Test
51+
run: ./tools/gha-run-tests.ps1
52+
53+
build:
54+
name: build/test on ubuntu-latest
55+
56+
runs-on: ubuntu-latest
57+
58+
services:
59+
rabbitmq:
60+
image: pivotalrabbitmq/rabbitmq:master-otp-max
61+
ports:
62+
- 5672:5672
63+
- 15672:15672
64+
65+
steps:
66+
- name: Clone repository
67+
uses: actions/checkout@v2
68+
with:
69+
submodules: true
70+
- name: Setup .NET
71+
uses: actions/setup-dotnet@v1
72+
with:
73+
dotnet-version: 3.1.x
74+
- name: Cache NuGet packages
75+
uses: actions/cache@v2
76+
with:
77+
path: |
78+
~/.nuget/packages
79+
~/.local/share/NuGet/v3-cache
80+
key: ${{ runner.os }}-v0-nuget-${{ hashFiles('**/*.csproj') }}
81+
restore-keys: |
82+
${{ runner.os }}-v0-nuget-
83+
- name: Restore
84+
run: dotnet restore --verbosity=normal
85+
- name: ApiGen
86+
run: dotnet run --project ./projects/Apigen/Apigen.csproj --apiName:AMQP_0_9_1 ./projects/specs/amqp0-9-1.stripped.xml ./gensrc/autogenerated-api-0-9-1.cs
87+
- name: Build
88+
run: dotnet build --no-restore --verbosity=normal
89+
- name: Test
90+
run: dotnet test --no-restore --no-build --logger "console;verbosity=detailed" --framework "netcoreapp3.1"
91+
env:
92+
RABBITMQ_RABBITMQCTL_PATH: DOCKER:${{job.services.rabbitmq.id}}

_site

Submodule _site updated 166 files

build.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@ECHO OFF
22
set DOTNET_CLI_TELEMETRY_OPTOUT=1
3-
dotnet restore .\RabbitMQDotNetClient.sln
4-
dotnet run --project .\projects\Apigen\Apigen.csproj --apiName:AMQP_0_9_1 .\projects\specs\amqp0-9-1.stripped.xml .\gensrc\autogenerated-api-0-9-1.cs
5-
dotnet build .\RabbitMQDotNetClient.sln
3+
dotnet restore --verbosity=normal .\RabbitMQDotNetClient.sln
4+
dotnet run --verbosity=normal --project .\projects\Apigen\Apigen.csproj --apiName:AMQP_0_9_1 .\projects\specs\amqp0-9-1.stripped.xml .\gensrc\autogenerated-api-0-9-1.cs
5+
dotnet build --verbosity=normal .\RabbitMQDotNetClient.sln

projects/RabbitMQ.Client/RabbitMQ.Client.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<PackageTags>rabbitmq, amqp</PackageTags>
1818
<Product>RabbitMQ</Product>
1919
<PublishRepositoryUrl>true</PublishRepositoryUrl>
20+
<RepositoryUrl>https://github.com/rabbitmq/rabbitmq-dotnet-client.git</RepositoryUrl>
2021
<IncludeSymbols>true</IncludeSymbols>
2122
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2223
<AssemblyOriginatorKeyFile>../rabbit.snk</AssemblyOriginatorKeyFile>

projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,14 @@ private static async Task HandleConcurrent(Work work, IModel model, SemaphoreSli
182182
finally
183183
{
184184
work.PostExecute();
185-
limiter.Release();
185+
186+
try
187+
{
188+
limiter.Release();
189+
}
190+
catch (ObjectDisposedException) // Prevents Exceptions in the Task's finalizer when the WorkPool is Stopped
191+
{
192+
}
186193
}
187194
}
188195

projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,24 @@ private bool TryPerformAutomaticRecovery()
451451
catch (Exception e)
452452
{
453453
ESLog.Error("Exception when recovering connection. Will try again after retry interval.", e);
454+
455+
try
456+
{
457+
/*
458+
* To prevent connection leaks on the next recovery loop,
459+
* we abort the delegated connection if it is still open.
460+
* We do not want to block the abort forever (potentially deadlocking recovery),
461+
* so we specify the same configured timeout used for connection.
462+
*/
463+
if (_delegate?.IsOpen == true)
464+
{
465+
_delegate.Abort(Constants.InternalError, "FailedAutoRecovery", ShutdownInitiator.Library, _factory.RequestedConnectionTimeout);
466+
}
467+
}
468+
catch (Exception e2)
469+
{
470+
ESLog.Warn("Exception when aborting previous auto recovery connection.", e2);
471+
}
454472
}
455473

456474
return false;
@@ -672,7 +690,6 @@ private void Init(IFrameHandler fh)
672690
lock (_eventLock)
673691
{
674692
ConnectionShutdown += recoveryListener;
675-
_recordedShutdownEventHandlers += recoveryListener;
676693
}
677694
}
678695

projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,19 @@ public void AutomaticallyRecover(AutorecoveringConnection conn, bool recoverCons
441441
newModel.TxSelect();
442442
}
443443

444+
/*
445+
* https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/1140
446+
* If this assignment is not done before recovering consumers, there is a good
447+
* chance that an invalid Model will be used to handle a basic.deliver frame,
448+
* with the resulting basic.ack never getting sent out.
449+
*/
450+
_delegate = newModel;
451+
444452
if (recoverConsumers)
445453
{
446454
_connection.RecoverConsumers(this, newModel);
447455
}
448456

449-
_delegate = newModel;
450457
RunRecoveryEventHandlers();
451458
}
452459

projects/RabbitMQ.Client/client/impl/Connection.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ public Connection(IConnectionFactory factory, bool insist, IFrameHandler frameHa
116116
_model0 = (ModelBase)Protocol.CreateModel(_session0);
117117

118118
StartMainLoop(factory.UseBackgroundThreadsForIO);
119-
Open(insist);
119+
try
120+
{
121+
Open(insist);
122+
}
123+
catch
124+
{
125+
TerminateMainloop();
126+
throw;
127+
}
120128
}
121129

122130
public Guid Id { get { return _id; } }

projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,18 @@ public void Close()
193193
try
194194
{
195195
_channelWriter.Complete();
196-
_writerTask.GetAwaiter().GetResult();
196+
_writerTask?.GetAwaiter().GetResult();
197197
}
198-
catch(Exception)
198+
catch
199199
{
200+
// ignore, we are closing anyway
200201
}
201202

202203
try
203204
{
204205
_socket.Close();
205206
}
206-
catch (Exception)
207+
catch
207208
{
208209
// ignore, we are closing anyway
209210
}

projects/Unit/APIApproval.Approve.verified.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,13 +847,13 @@ namespace RabbitMQ.Client.Logging
847847
{
848848
public static RabbitMQ.Client.Logging.RabbitMqClientEventSource Log;
849849
public RabbitMqClientEventSource() { }
850-
[System.Diagnostics.Tracing.Event(3, Keywords=System.Diagnostics.Tracing.EventKeywords.None | System.Diagnostics.Tracing.EventKeywords.All, Level=System.Diagnostics.Tracing.EventLevel.Error, Message="ERROR")]
850+
[System.Diagnostics.Tracing.Event(3, Keywords=System.Diagnostics.Tracing.EventKeywords.None, Level=System.Diagnostics.Tracing.EventLevel.Error, Message="ERROR")]
851851
public void Error(string message, RabbitMQ.Client.Logging.RabbitMqExceptionDetail ex) { }
852852
[System.Diagnostics.Tracing.NonEvent]
853853
public void Error(string message, System.Exception ex) { }
854-
[System.Diagnostics.Tracing.Event(1, Keywords=System.Diagnostics.Tracing.EventKeywords.None | System.Diagnostics.Tracing.EventKeywords.All, Level=System.Diagnostics.Tracing.EventLevel.Informational, Message="INFO")]
854+
[System.Diagnostics.Tracing.Event(1, Keywords=System.Diagnostics.Tracing.EventKeywords.None, Level=System.Diagnostics.Tracing.EventLevel.Informational, Message="INFO")]
855855
public void Info(string message) { }
856-
[System.Diagnostics.Tracing.Event(2, Keywords=System.Diagnostics.Tracing.EventKeywords.None | System.Diagnostics.Tracing.EventKeywords.All, Level=System.Diagnostics.Tracing.EventLevel.Warning, Message="WARN")]
856+
[System.Diagnostics.Tracing.Event(2, Keywords=System.Diagnostics.Tracing.EventKeywords.None, Level=System.Diagnostics.Tracing.EventLevel.Warning, Message="WARN")]
857857
public void Warn(string message) { }
858858
public class Keywords
859859
{

projects/Unit/APIApproval.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
namespace RabbitMQ.Client.Unit
3939
{
4040
[TestFixture]
41-
[Platform(Exclude="Mono")]
41+
[Platform(Exclude="Mono,Linux")]
4242
public class APIApproval
4343
{
4444
[Test]

projects/Unit/Fixtures.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ internal void StopRabbitMQ()
675675
internal void StartRabbitMQ()
676676
{
677677
ExecRabbitMQCtl("start_app");
678+
ExecRabbitMQCtl("await_startup");
678679
}
679680

680681
//

projects/Unit/TestConnectionRecovery.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public void CleanUp()
7575
}
7676

7777
[Test]
78-
[Ignore("TODO flaky")]
7978
public void TestBasicAckAfterChannelRecovery()
8079
{
8180
var allMessagesSeenLatch = new ManualResetEventSlim(false);
@@ -98,7 +97,6 @@ public void TestBasicAckAfterChannelRecovery()
9897
}
9998

10099
[Test]
101-
[Ignore("TODO flaky")]
102100
public void TestBasicNackAfterChannelRecovery()
103101
{
104102
var allMessagesSeenLatch = new ManualResetEventSlim(false);
@@ -121,7 +119,6 @@ public void TestBasicNackAfterChannelRecovery()
121119
}
122120

123121
[Test]
124-
[Ignore("TODO flaky")]
125122
public void TestBasicRejectAfterChannelRecovery()
126123
{
127124
var allMessagesSeenLatch = new ManualResetEventSlim(false);
@@ -839,23 +836,23 @@ public void TestPublishRpcRightAfterReconnect()
839836
var properties = Model.CreateBasicProperties();
840837
properties.ReplyTo = "amq.rabbitmq.reply-to";
841838

842-
bool done = false;
839+
TimeSpan doneSpan = TimeSpan.FromMilliseconds(100);
840+
var done = new ManualResetEventSlim(false);
843841
var t = new Thread(() =>
844842
{
845843
try
846844
{
847845

848846
CloseAndWaitForRecovery();
849-
Thread.Sleep(100);
850847
}
851848
finally
852849
{
853-
done = true;
850+
done.Set();
854851
}
855852
});
856853
t.Start();
857854

858-
while (!done)
855+
while (!done.IsSet)
859856
{
860857
try
861858
{
@@ -869,9 +866,8 @@ public void TestPublishRpcRightAfterReconnect()
869866
Assert.AreNotEqual(406, a.ShutdownReason.ReplyCode);
870867
}
871868
}
872-
Thread.Sleep(1);
869+
done.Wait(doneSpan);
873870
}
874-
875871
t.Join();
876872
}
877873

projects/Unit/Unit.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
15-
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
15+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
1616
<PackageReference Include="NUnit" Version="3.13.2" />
17-
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
18-
<PackageReference Include="PublicApiGenerator" Version="10.2.0" />
19-
<PackageReference Include="Verify.NUnit" Version="11.18.2" />
17+
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
18+
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
19+
<PackageReference Include="Verify.NUnit" Version="12.2" />
2020
</ItemGroup>
2121

2222
</Project>

tools/gha-run-tests.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
$ProgressPreference = 'Continue'
2+
$ErrorActionPreference = 'Stop'
3+
Set-StrictMode -Version 2.0
4+
5+
$erlang_reg_path = 'HKLM:\SOFTWARE\Ericsson\Erlang'
6+
if (Test-Path 'HKLM:\SOFTWARE\WOW6432Node\')
7+
{
8+
$erlang_reg_path = 'HKLM:\SOFTWARE\WOW6432Node\Ericsson\Erlang'
9+
}
10+
$erlang_erts_version = Get-ChildItem -Path $erlang_reg_path -Name
11+
$erlang_home = (Get-ItemProperty -LiteralPath $erlang_reg_path\$erlang_erts_version).'(default)'
12+
13+
Write-Host "[INFO] Setting ERLANG_HOME to '$erlang_home'..."
14+
$env:ERLANG_HOME = $erlang_home
15+
[Environment]::SetEnvironmentVariable('ERLANG_HOME', $erlang_home, 'Machine')
16+
17+
$regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ'
18+
if (Test-Path 'HKLM:\SOFTWARE\WOW6432Node\')
19+
{
20+
$regPath = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ'
21+
}
22+
23+
$rabbitmq_base_path = Split-Path -Parent (Get-ItemProperty $regPath 'UninstallString').UninstallString
24+
$rabbitmq_version = (Get-ItemProperty $regPath "DisplayVersion").DisplayVersion
25+
$rabbitmqctl_path = Join-Path -Path $rabbitmq_base_path -ChildPath "rabbitmq_server-$rabbitmq_version" | Join-Path -ChildPath 'sbin' | Join-Path -ChildPath 'rabbitmqctl.bat'
26+
27+
Write-Host "[INFO] Setting RABBITMQ_RABBITMQCTL_PATH to '$rabbitmqctl_path'..."
28+
$env:RABBITMQ_RABBITMQCTL_PATH = $rabbitmqctl_path
29+
[Environment]::SetEnvironmentVariable('RABBITMQ_RABBITMQCTL_PATH', $rabbitmqctl_path, 'Machine')
30+
31+
$solution_file = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'RabbitMQDotNetClient.sln'
32+
dotnet test --no-restore --no-build --logger "console;verbosity=detailed" $solution_file

0 commit comments

Comments
 (0)