diff --git a/src/AWS.Deploy.ServerMode.Client/ServerModeSession.cs b/src/AWS.Deploy.ServerMode.Client/ServerModeSession.cs index e9ce6c337..2c6b60c3b 100644 --- a/src/AWS.Deploy.ServerMode.Client/ServerModeSession.cs +++ b/src/AWS.Deploy.ServerMode.Client/ServerModeSession.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Net.Http; +using System.Net.NetworkInformation; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; @@ -126,6 +127,14 @@ public async Task Start(CancellationToken cancellationToken) for (var port = _startPort; port <= _endPort; port++) { + // This ensures that deploy tool CLI doesn't try on the in-use port + // because server availability task will return success response for + // an in-use port + if (IsPortInUse(port)) + { + continue; + } + _aes = Aes.Create(); _aes.GenerateKey(); @@ -216,6 +225,14 @@ private Task IsServerAvailable(CancellationToken cancellationToken) cancellationToken); } + private static bool IsPortInUse(int port) + { + var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); + var listeners = ipGlobalProperties.GetActiveTcpListeners(); + + return listeners.Any(x => x.Port == port); + } + #endregion #region Disposable diff --git a/version.json b/version.json index a9b9390fb..bc8aec0c6 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "0.24", + "version": "0.25", "publicReleaseRefSpec": [ ".*" ],