Skip to content

Commit f62dcda

Browse files
committed
Use Get-Random to help ensure unique fw rule names
1 parent 4c1282d commit f62dcda

File tree

9 files changed

+52
-52
lines changed

9 files changed

+52
-52
lines changed

.ci/windows/gha-setup.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ New-Variable -Name allowedExes -Option Constant -Value @('erl.exe', 'epmd.exe',
102102
New-Variable -Name exes -Option Constant -Value `
103103
$(Get-ChildItem -Filter '*.exe' -Recurse -LiteralPath $erlangProgramFilesPath | Where-Object { $_.Name -in $allowedExes })
104104

105-
Get-NetFirewallRule -PolicyStore ActiveStore
106-
107105
foreach ($exe in $exes) {
108-
Write-Verbose "Updating or creating firewall rule for '$exe'"
109-
$fwRuleName = "rabbitmq-allow-$($exe.Name)"
106+
$fwRuleName = "rabbitmq-allow-$($exe.Name)-$(Get-Random)"
107+
Write-Verbose "Updating or creating firewall rule for '$exe' - fwRuleName: $fwRuleName"
110108
if (!(Get-NetFirewallRule -ErrorAction 'SilentlyContinue' -Name $fwRuleName)) {
111109
New-NetFirewallRule -Enabled True -Name $fwRuleName -DisplayName $fwRuleName -Direction In -Program $exe -Profile Any -Action Allow
112110
}

projects/RabbitMQ.Client/client/api/ConnectionFactory.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public IConnection CreateConnection()
426426
/// When the configured hostname was not reachable.
427427
/// </exception>
428428
public ValueTask<IConnection> CreateConnectionAsync(
429-
CancellationToken cancellationToken = default(CancellationToken))
429+
CancellationToken cancellationToken = default)
430430
{
431431
return CreateConnectionAsync(ClientProvidedName, cancellationToken);
432432
}
@@ -466,7 +466,7 @@ public IConnection CreateConnection(string clientProvidedName)
466466
/// When the configured hostname was not reachable.
467467
/// </exception>
468468
public ValueTask<IConnection> CreateConnectionAsync(string clientProvidedName,
469-
CancellationToken cancellationToken = default(CancellationToken))
469+
CancellationToken cancellationToken = default)
470470
{
471471
return CreateConnectionAsync(EndpointResolverFactory(LocalEndpoints()), clientProvidedName, cancellationToken);
472472
}
@@ -506,7 +506,7 @@ public IConnection CreateConnection(IEnumerable<string> hostnames)
506506
/// When no hostname was reachable.
507507
/// </exception>
508508
public ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames,
509-
CancellationToken cancellationToken = default(CancellationToken))
509+
CancellationToken cancellationToken = default)
510510
{
511511
return CreateConnectionAsync(hostnames, ClientProvidedName, cancellationToken);
512512
}
@@ -559,7 +559,7 @@ public IConnection CreateConnection(IEnumerable<string> hostnames, string client
559559
/// When no hostname was reachable.
560560
/// </exception>
561561
public ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, string clientProvidedName,
562-
CancellationToken cancellationToken = default(CancellationToken))
562+
CancellationToken cancellationToken = default)
563563
{
564564
IEnumerable<AmqpTcpEndpoint> endpoints = hostnames.Select(h => new AmqpTcpEndpoint(h, Port, Ssl, MaxMessageSize));
565565
return CreateConnectionAsync(EndpointResolverFactory(endpoints), clientProvidedName, cancellationToken);
@@ -598,7 +598,7 @@ public IConnection CreateConnection(IEnumerable<AmqpTcpEndpoint> endpoints)
598598
/// When no hostname was reachable.
599599
/// </exception>
600600
public ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints,
601-
CancellationToken cancellationToken = default(CancellationToken))
601+
CancellationToken cancellationToken = default)
602602
{
603603
return CreateConnectionAsync(endpoints, ClientProvidedName, cancellationToken);
604604
}
@@ -648,7 +648,7 @@ public IConnection CreateConnection(IEnumerable<AmqpTcpEndpoint> endpoints, stri
648648
/// When no hostname was reachable.
649649
/// </exception>
650650
public ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, string clientProvidedName,
651-
CancellationToken cancellationToken = default(CancellationToken))
651+
CancellationToken cancellationToken = default)
652652
{
653653
return CreateConnectionAsync(EndpointResolverFactory(endpoints), clientProvidedName, cancellationToken);
654654
}
@@ -687,9 +687,9 @@ public IConnection CreateConnection(IEndpointResolver endpointResolver, string c
687687
return (Connection)c.Open();
688688
}
689689
}
690-
catch (Exception e)
690+
catch (Exception ex)
691691
{
692-
throw new BrokerUnreachableException(e);
692+
throw new BrokerUnreachableException(ex);
693693
}
694694
}
695695

@@ -711,7 +711,7 @@ public IConnection CreateConnection(IEndpointResolver endpointResolver, string c
711711
/// When no hostname was reachable.
712712
/// </exception>
713713
public async ValueTask<IConnection> CreateConnectionAsync(IEndpointResolver endpointResolver, string clientProvidedName,
714-
CancellationToken cancellationToken = default(CancellationToken))
714+
CancellationToken cancellationToken = default)
715715
{
716716
ConnectionConfig config = CreateConfig(clientProvidedName);
717717
try
@@ -731,19 +731,20 @@ public async ValueTask<IConnection> CreateConnectionAsync(IEndpointResolver endp
731731
.ConfigureAwait(false);
732732
}
733733
}
734-
// TODO is this correct?
735-
catch (TaskCanceledException)
734+
catch (OperationCanceledException ex)
736735
{
737-
throw;
738-
}
739-
// TODO is this correct?
740-
catch (AggregateException)
741-
{
742-
throw;
736+
if (cancellationToken.IsCancellationRequested)
737+
{
738+
throw;
739+
}
740+
else
741+
{
742+
throw new BrokerUnreachableException(ex);
743+
}
743744
}
744-
catch (Exception e)
745+
catch (Exception ex)
745746
{
746-
throw new BrokerUnreachableException(e);
747+
throw new BrokerUnreachableException(ex);
747748
}
748749
}
749750

projects/RabbitMQ.Client/client/api/DefaultEndpointResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace RabbitMQ.Client
3838
public class DefaultEndpointResolver : IEndpointResolver
3939
{
4040
#if !NET6_0_OR_GREATER
41-
private static readonly Random s_rnd = new Random();
41+
private readonly Random s_rnd = new Random();
4242
#endif
4343
private readonly List<AmqpTcpEndpoint> _endpoints;
4444

projects/RabbitMQ.Client/client/api/IConnectionFactory.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public interface IConnectionFactory
107107
/// Asynchronously create a connection to the specified endpoint.
108108
/// </summary>
109109
/// <param name="cancellationToken">Cancellation token for this connection</param>
110-
ValueTask<IConnection> CreateConnectionAsync(CancellationToken cancellationToken);
110+
ValueTask<IConnection> CreateConnectionAsync(CancellationToken cancellationToken = default);
111111

112112
/// <summary>
113113
/// Create a connection to the specified endpoint.
@@ -132,7 +132,7 @@ public interface IConnectionFactory
132132
/// </param>
133133
/// <param name="cancellationToken">Cancellation token for this connection</param>
134134
/// <returns>Open connection</returns>
135-
ValueTask<IConnection> CreateConnectionAsync(string clientProvidedName, CancellationToken cancellationToken);
135+
ValueTask<IConnection> CreateConnectionAsync(string clientProvidedName, CancellationToken cancellationToken = default);
136136

137137
/// <summary>
138138
/// Connects to the first reachable hostname from the list.
@@ -147,7 +147,7 @@ public interface IConnectionFactory
147147
/// <param name="hostnames">List of host names to use</param>
148148
/// <param name="cancellationToken">Cancellation token for this connection</param>
149149
/// <returns>Open connection</returns>
150-
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, CancellationToken cancellationToken);
150+
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, CancellationToken cancellationToken = default);
151151

152152
/// <summary>
153153
/// Connects to the first reachable hostname from the list.
@@ -175,7 +175,7 @@ public interface IConnectionFactory
175175
/// <param name="cancellationToken">Cancellation token for this connection</param>
176176
/// <returns>Open connection</returns>
177177
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, string clientProvidedName,
178-
CancellationToken cancellationToken);
178+
CancellationToken cancellationToken = default);
179179

180180
/// <summary>
181181
/// Create a connection using a list of endpoints.
@@ -204,7 +204,7 @@ ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, stri
204204
/// <exception cref="BrokerUnreachableException">
205205
/// When no hostname was reachable.
206206
/// </exception>
207-
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, CancellationToken cancellationToken);
207+
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, CancellationToken cancellationToken = default);
208208

209209
/// <summary>
210210
/// Create a connection using a list of endpoints.
@@ -246,7 +246,7 @@ ValueTask<IConnection> CreateConnectionAsync(IEnumerable<string> hostnames, stri
246246
/// When no hostname was reachable.
247247
/// </exception>
248248
ValueTask<IConnection> CreateConnectionAsync(IEnumerable<AmqpTcpEndpoint> endpoints, string clientProvidedName,
249-
CancellationToken cancellationToken);
249+
CancellationToken cancellationToken = default);
250250

251251
/// <summary>
252252
/// Amount of time protocol handshake operations are allowed to take before

projects/RabbitMQ.Client/client/api/IEndpointResolverExtensions.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static async Task<T> SelectOneAsync<T>(this IEndpointResolver resolver,
4242
Func<AmqpTcpEndpoint, CancellationToken, Task<T>> selector, CancellationToken cancellationToken)
4343
{
4444
var t = default(T);
45-
List<Exception> exceptions = null;
45+
List<Exception> exceptions = [];
4646
foreach (AmqpTcpEndpoint ep in resolver.All())
4747
{
4848
try
@@ -53,23 +53,24 @@ public static async Task<T> SelectOneAsync<T>(this IEndpointResolver resolver,
5353
return t;
5454
}
5555
}
56-
// TODO immediate re-throw vs trying the next host?
57-
catch (TaskCanceledException)
56+
catch (OperationCanceledException ex)
5857
{
59-
throw;
60-
}
61-
catch (AggregateException)
62-
{
63-
throw;
58+
if (cancellationToken.IsCancellationRequested)
59+
{
60+
throw;
61+
}
62+
else
63+
{
64+
exceptions.Add(ex);
65+
}
6466
}
6567
catch (Exception e)
6668
{
67-
exceptions ??= new List<Exception>(1);
6869
exceptions.Add(e);
6970
}
7071
}
7172

72-
if (Object.Equals(t, default(T)) && exceptions?.Count > 0)
73+
if (Object.Equals(t, default(T)) && exceptions.Count > 0)
7374
{
7475
throw new AggregateException(exceptions);
7576
}

projects/RabbitMQ.Client/client/api/ITcpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface ITcpClient : IDisposable
1919

2020
Socket Client { get; }
2121

22-
Task ConnectAsync(IPAddress host, int port, CancellationToken cancellationToken);
22+
Task ConnectAsync(IPAddress host, int port, CancellationToken cancellationToken = default);
2323

2424
NetworkStream GetStream();
2525

projects/RabbitMQ.Client/client/api/TcpClientAdapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public TcpClientAdapter(Socket socket)
2121
}
2222

2323
#if NET6_0_OR_GREATER
24-
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken)
24+
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken = default)
2525
{
2626
AssertSocket();
2727
return _sock.ConnectAsync(ep, port, cancellationToken).AsTask();
2828
}
2929
#else
30-
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken)
30+
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken = default)
3131
{
3232
return _sock.ConnectAsync(ep, port).WithCancellation(cancellationToken);
3333
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private async ValueTask StartAndTuneAsync(CancellationToken cancellationToken)
7474
{
7575
var connectionStartCell = new TaskCompletionSource<ConnectionStartDetails>(TaskCreationOptions.RunContinuationsAsynchronously);
7676

77-
cancellationToken.Register(() =>
77+
using CancellationTokenRegistration ctr = cancellationToken.Register(() =>
7878
{
7979
if (connectionStartCell.TrySetCanceled())
8080
{

projects/Test/Unit/APIApproval.Approve.verified.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,12 @@ namespace RabbitMQ.Client
599599
RabbitMQ.Client.IConnection CreateConnection(string clientProvidedName);
600600
RabbitMQ.Client.IConnection CreateConnection(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, string clientProvidedName);
601601
RabbitMQ.Client.IConnection CreateConnection(System.Collections.Generic.IEnumerable<string> hostnames, string clientProvidedName);
602-
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Threading.CancellationToken cancellationToken);
603-
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, System.Threading.CancellationToken cancellationToken);
604-
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<string> hostnames, System.Threading.CancellationToken cancellationToken);
605-
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(string clientProvidedName, System.Threading.CancellationToken cancellationToken);
606-
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, string clientProvidedName, System.Threading.CancellationToken cancellationToken);
607-
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<string> hostnames, string clientProvidedName, System.Threading.CancellationToken cancellationToken);
602+
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Threading.CancellationToken cancellationToken = default);
603+
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, System.Threading.CancellationToken cancellationToken = default);
604+
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<string> hostnames, System.Threading.CancellationToken cancellationToken = default);
605+
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(string clientProvidedName, System.Threading.CancellationToken cancellationToken = default);
606+
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<RabbitMQ.Client.AmqpTcpEndpoint> endpoints, string clientProvidedName, System.Threading.CancellationToken cancellationToken = default);
607+
System.Threading.Tasks.ValueTask<RabbitMQ.Client.IConnection> CreateConnectionAsync(System.Collections.Generic.IEnumerable<string> hostnames, string clientProvidedName, System.Threading.CancellationToken cancellationToken = default);
608608
}
609609
public interface ICredentialsProvider
610610
{
@@ -712,7 +712,7 @@ namespace RabbitMQ.Client
712712
bool Connected { get; }
713713
System.TimeSpan ReceiveTimeout { get; set; }
714714
void Close();
715-
System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress host, int port, System.Threading.CancellationToken cancellationToken);
715+
System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress host, int port, System.Threading.CancellationToken cancellationToken = default);
716716
System.Net.Sockets.NetworkStream GetStream();
717717
}
718718
public class PlainMechanism : RabbitMQ.Client.IAuthMechanism
@@ -833,7 +833,7 @@ namespace RabbitMQ.Client
833833
public virtual bool Connected { get; }
834834
public virtual System.TimeSpan ReceiveTimeout { get; set; }
835835
public virtual void Close() { }
836-
public virtual System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress ep, int port, System.Threading.CancellationToken cancellationToken) { }
836+
public virtual System.Threading.Tasks.Task ConnectAsync(System.Net.IPAddress ep, int port, System.Threading.CancellationToken cancellationToken = default) { }
837837
public void Dispose() { }
838838
protected virtual void Dispose(bool disposing) { }
839839
public virtual System.Net.Sockets.NetworkStream GetStream() { }

0 commit comments

Comments
 (0)