File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,11 @@ public static int StartDebugProxy(string devToolsHost)
3838 //on managed code will freeze because it will not be able to continue executing the BrowserDebugProxy to get the locals value
3939 var executablePath = Path . Combine ( System . AppContext . BaseDirectory , "BrowserDebugHost.dll" ) ;
4040 var ownerPid = Environment . ProcessId ;
41- var generateRandomPort = new Random ( ) . Next ( 5000 , 5300 ) ;
41+ // generate a random port in a given range, skipping the ports blocked by browsers: https://chromestatus.com/feature/5064283639513088
42+ var generateRandomPort = GetNextRandomExcept ( 5000 ..5300 ,
43+ 5060 , // SIP
44+ 5061 // SIPS
45+ ) ;
4246 var processStartInfo = new ProcessStartInfo
4347 {
4448 FileName = "dotnet" + ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? ".exe" : "" ) ,
@@ -52,6 +56,17 @@ public static int StartDebugProxy(string devToolsHost)
5256 throw new InvalidOperationException ( "Unable to start debug proxy process." ) ;
5357 }
5458 return generateRandomPort ;
59+
60+ static int GetNextRandomExcept ( Range range , params int [ ] except )
61+ {
62+ int current ;
63+ do
64+ {
65+ current = Random . Shared . Next ( range . Start . Value , range . End . Value ) ;
66+ } while ( Array . IndexOf ( except , current ) > - 1 ) ;
67+
68+ return current ;
69+ }
5570 }
5671
5772 public void Configure ( IApplicationBuilder app ,
You can’t perform that action at this time.
0 commit comments