Response.Flush in classic ASP calling TIME_WAIT ports

I recently found out about this issue: https://blogs.msdn.microsoft.com/spike/2008/09/17/nested-recordset-and-the-portsocket-in-time_wait-problem-by-example/

If you open a recordset, then use the connection for something else, while the recordset is still open, the web server opens a new port for talking to the database, and then immediately puts this port in TIME_WAIT state.

I went through the site to fix this (closing the records before the connection was reused - it works), but noticed something strange.

If there is “Response.Flush” on the page, no matter what you do, this results in the use of an additional port, and then it is put into a useless TIME_WAIT state. This can lead to a serious case of port depletion.

SAMPLE CODE:

 <%@ Language=VBScript %>

 <html>

<head>

</head>

<body>
<%
response.flush 

set cnn = server.CreateObject("adodb.connection")

CNN.cursorlocation=3
cnn.open [YOUR CONNECTION STRING]

set rs=server.createobject("adodb.recordset")
set rs=cnn.execute("select top 1 * from [YOUR TABLE]")





cnn.close
set cnn=nothing
%>


</body>
</html>

To check the timeout, you can run:

netstat -nao | find /i "[YOUR DB IP]" /c

via the command line on the web server. Assuming this is a test system, you should immediately see the time_wait pop-ups from your web server to your database server. Remove the flash and it will stop.

Googling did not help - open any offers.

Environment: IIS 7.5, classic ASP, SQL Server 2008.

EDIT:

I also tried this according to the comments:

Set cmd = Server.CreateObject("ADODB.Command")
With cmd
  'No need to handle connection let ADODB.Command create and destory it.
  .ActiveConnection = sqlcnnstr1
  .CommandType = 1
  .CommandText = "select top 1 * from [YOUR_TABLE]"
  Set rs = .Execute()
  If Not rs.EOF Then data = rs.GetRows()
  Call rs.Close()
  Set rs = Nothing
End with
Set cmd = Nothing

Still the same problem. With flash, additional connection, without the same connection.

2 , . JUST response.flush, , , IIS , .

: not, response.flush IIS .

+4
1

, TIME_WAIT , . flush - , , TIME_WAIT, , .flush , .

+1

Source: https://habr.com/ru/post/1651329/


All Articles