Skip to content

Commit 5880415

Browse files
committed
Do not add a default address
1 parent f95bff3 commit 5880415

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/Servers/HttpSys/samples/QueueSharing/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public static void Main(string[] args)
4040
{
4141
webHost.UseHttpSys(options =>
4242
{
43-
options.UrlPrefixes.Add("http://localhost:5000");
43+
// Skipping this to ensure the server works without any prefixes in attach mode.
44+
if (mode != RequestQueueMode.Attach)
45+
{
46+
options.UrlPrefixes.Add("http://localhost:5002");
47+
}
4448
options.RequestQueueName = "QueueName";
4549
options.RequestQueueMode = mode;
4650
options.MaxAccepts = 1; // Better load rotation between instances.

src/Servers/HttpSys/src/MessagePump.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ public Task StartAsync<TContext>(IHttpApplication<TContext> application, Cancell
112112
Listener.Options.UrlPrefixes.Add(value);
113113
}
114114
}
115-
else
115+
else if (Listener.RequestQueue.Created)
116116
{
117117
LogHelper.LogDebug(_logger, $"No listening endpoints were configured. Binding to {Constants.DefaultServerAddress} by default.");
118118

119119
_serverAddresses.Addresses.Add(Constants.DefaultServerAddress);
120120
Listener.Options.UrlPrefixes.Add(Constants.DefaultServerAddress);
121121
}
122+
// else // Attaching to an existing queue, don't add a default.
122123

123124
// Can't call Start twice
124125
Contract.Assert(_application == null);

src/Servers/HttpSys/test/FunctionalTests/ServerTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Text;
1212
using System.Threading;
1313
using System.Threading.Tasks;
14+
using Microsoft.AspNetCore.Hosting.Server.Features;
1415
using Microsoft.AspNetCore.Http;
1516
using Microsoft.AspNetCore.HttpSys.Internal;
1617
using Microsoft.AspNetCore.Testing;
@@ -625,6 +626,25 @@ public async Task Server_StopAsyncCalledWithNoRequests_Success()
625626
}
626627
}
627628

629+
[ConditionalFact]
630+
public async Task Server_AttachToExistingQueue_NoIServerAddresses_NoDefaultAdded()
631+
{
632+
var queueName = Guid.NewGuid().ToString();
633+
using var server = Utilities.CreateHttpServer(out var address, httpContext => Task.CompletedTask, options =>
634+
{
635+
options.RequestQueueName = queueName;
636+
});
637+
using var attachedServer = Utilities.CreatePump(options =>
638+
{
639+
options.RequestQueueName = queueName;
640+
options.RequestQueueMode = RequestQueueMode.Attach;
641+
});
642+
await attachedServer.StartAsync(new DummyApplication(context => Task.CompletedTask), default);
643+
var addressesFeature = attachedServer.Features.Get<IServerAddressesFeature>();
644+
Assert.Empty(addressesFeature.Addresses);
645+
Assert.Empty(attachedServer.Listener.Options.UrlPrefixes);
646+
}
647+
628648
private async Task<string> SendRequestAsync(string uri)
629649
{
630650
using (HttpClient client = new HttpClient() { Timeout = Utilities.DefaultTimeout })

0 commit comments

Comments
 (0)