Просмотр исходного кода

Bump up the MIN_PORT for ANCM out of process (#46432)

Xurui Yan 3 лет назад
Родитель
Сommit
43bcdae138

+ 3 - 3
src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp

@@ -113,13 +113,13 @@ SERVER_PROCESS::GetRandomPort
     BOOL    fPortInUse = FALSE;
     DWORD   dwActualProcessId = 0;
 
-    std::uniform_int_distribution<> dist(MIN_PORT, MAX_PORT);
+    std::uniform_int_distribution<> dist(MIN_PORT_RANDOM, MAX_PORT);
 
     if (g_fNsiApiNotSupported)
     {
         //
         // the default value for optional parameter dwExcludedPort is 0 which is reserved
-        // a random number between MIN_PORT and MAX_PORT
+        // a random number between MIN_PORT_RANDOM and MAX_PORT
         //
         while ((*pdwPickedPort = dist(m_randomGenerator)) == dwExcludedPort);
     }
@@ -224,7 +224,7 @@ Finished:
             m_struAppFullPath.QueryStr(),
             m_struPhysicalPath.QueryStr(),
             m_dwPort,
-            MIN_PORT,
+            MIN_PORT_RANDOM,
             MAX_PORT,
             hr);
     }

+ 8 - 0
src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.h

@@ -6,7 +6,15 @@
 #include <random>
 #include <map>
 
+// Minimum port number that can be used.
+// This is lower than 'MIN_PORT_RANDOM' since we allow people to choose
+// low-numbered ports when they are not using random assignment.
 #define MIN_PORT                                    1025
+// Minimum number used for automatic random port assignment.
+// This value is somewhat arbitrary. Fixed-port services tend to
+// use ports near the minimum (1025) so this number is much higher
+// to reduce the chance of collisions.
+#define MIN_PORT_RANDOM                             10000
 #define MAX_PORT                                    48000
 #define MAX_RETRY                                   10
 #define MAX_ACTIVE_CHILD_PROCESSES                  16

+ 0 - 2
src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/requesthandler_config.h

@@ -32,8 +32,6 @@
 
 #define MAX_RAPID_FAILS_PER_MINUTE 100
 #define MILLISECONDS_IN_ONE_SECOND 1000
-#define MIN_PORT                   1025
-#define MAX_PORT                   48000
 
 #define TIMESPAN_IN_MILLISECONDS(x)  ((x)/((LONGLONG)(10000)))
 #define TIMESPAN_IN_SECONDS(x)       ((TIMESPAN_IN_MILLISECONDS(x))/((LONGLONG)(1000)))