question

JeremyMartin-8810 avatar image
0 Votes"
JeremyMartin-8810 asked BruceZhang-MSFT commented

IIS Duplicate %HTTP_PLATFORM_PORT%

Hi,

IIS Version: 10.0.14393.0
OS: Windows Server 2016

Have a website with a custom http binding 8000 and under this we have ~13 different web applications. Each application uses the same pool.

In the web.config of each application folder we have the following;


  <handlers>
       <add name="ProcessHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
     </handlers>
    
     <httpPlatform processPath=".\run.bat"
                   arguments="%HTTP_PLATFORM_PORT%"
                   startupTimeLimit="60"
                   processesPerApplication="1">
       <environmentVariables>
         <environmentVariable name="SERVER_PORT" value="%HTTP_PLATFORM_PORT%" />
       </environmentVariables>
     </httpPlatform>

The reason for this is we run a python module that is called through run.bat.

What we have noticed is when requests are made concurrently to the different web applications on start up duplicate port numbers are being allocated to %HTTP_PLATFORM_PORT%. This was confirmed by watching the process path and arguments being supplied to the batch file.

The result of this is for a brief period of time there are multiple python processes running on the same port. I say brief because something detects this port duplication and kills the offending process which results in the application being restarted under a new port.

The downside of this process is our first requests are either coming back with a 502 (Bad Gateway) or a 404 (Not Found)

We can explain why this is happening as sometimes the web application does not retry hence there is no application running. The 404 can be explained because of the two modules utilising the same port. A request comes in for a specific url/module and the other module is responding.

Definitely appears to be a timing issue as if we space our requests out then the modules get allocated a different port.

Hoping somebody can shed light on this issue.

EDIT

Further to this changing from httpPlatformHandler to AspNetCoreModuleV2 seemed to resolve the issue

      <handlers>
         <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
       </handlers>
    
     <aspNetCore processPath=".\run.bat"
                   arguments="%ASPNETCORE_PORT%"
                   startupTimeLimit="60"
                   processesPerApplication="1">
       <environmentVariables>
         <environmentVariable name="SERVER_PORT" value="%ASPNETCORE_PORT%" />
       </environmentVariables>
     </aspNetCore>

However I would like to know how the two modules select a free port and whether this is likely to occur again.

Thanks

windows-server-iis
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JeremyMartin-8810 ,

I would recommend that you have a separate application pool for each application, so that each application can have a separate process and not affect each other as before.

0 Votes 0 ·

Thanks @BruceZhang-MSFT,


We did initially think of that but as we eventually will have upwards of 50 applications we thought the memory overhead of each application having it's own pool would be troublesome.

When you say separate process for each pool does it work like that when its loading an external module? What I mean by that is in Task Manager I see multiple instances of my python application all running on separate PID and ports.

0 Votes 0 ·

Hi @JeremyMartin-8810 ,

When you deploy multiple applications in an application pool, the isolation of the application pool will allow each application to use an independent process and ensure that the processes do not affect each other. However, if the number of applications is particularly large, isolation will not be guaranteed. Therefore, in comparison, using a separate application pool for each application will ensure that one application is one process and does not affect each other.

0 Votes 0 ·
Show more comments

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered Bruce-SqlWork commented

Unlike Unix, window does not kill sub processes when the parent is killed. Most likely, IIS is probably detecting a startup error and killing the child process. It assumes this will free the port. But it is only killing the bat file and leaving the process running, so the port and request are still running.

Maybe your startup timeout is too short. You really should run the python app directly.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

From my investigation. When the URL's are hit and run.bat is called concurrently, every python executable is being passed the same port. At that point something detects this as a problem and all but one of the python executables are killed and restarted under another port. This than repeats until all applications are running on a separate port.

Interesting idea about running the python app directly... I will see if this has a different outcome.

0 Votes 0 ·
Bruce-SqlWork avatar image Bruce-SqlWork JeremyMartin-8810 ·

the python apps are probably exiting with port in use errors.

be sure the bat file is not running the app in background or the python app is not doing a fork.


1 Vote 1 ·