N
Nicholas Paldino [.NET/C# MVP]
AA,
I found the following in an article about SQL server and connecting to
it:
Note that the SQL Server network library specifically does not enable the
SO_REUSEADDR TCP/IP socket option for security reasons. When SO_REUSEADDR is
enabled, a malicious user can hijack a client port to SQL Server and use the
credentials that the client supplies to gain access to the computer that is
running SQL Server. By default, because the SQL Server network library does
not enable the SO_REUSEADDR socket option, every time you open and close a
socket through the SQL Server network library on the client side, the socket
enters a TIME_WAIT state for four minutes. If you are rapidly opening and
closing SQL Server connections over TCP/IP with pooling disabled, you are
rapidly opening and closing TCP/IP sockets. In other words, each SQL Server
connection has one TCP/IP socket. If you rapidly open and close 4000 sockets
in less than four minutes, you will reach the default maximum setting for
client anonymous ports, and new socket connection attempts fail until the
existing set of TIME_WAIT sockets times out.
While you are not using SQL server, it is the same problem you are
having. What you can do is set the following value in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpTim
edWaitDelay
You can set the value to the number of seconds to wait before the socket
is usable again.
However, setting this can have detrimental effects. Is there a need to
open a few thousand client connections? Can it be done a different, and
more efficient way? Setting the above value is dangerous because it is
machine-wide.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com
I found the following in an article about SQL server and connecting to
it:
Note that the SQL Server network library specifically does not enable the
SO_REUSEADDR TCP/IP socket option for security reasons. When SO_REUSEADDR is
enabled, a malicious user can hijack a client port to SQL Server and use the
credentials that the client supplies to gain access to the computer that is
running SQL Server. By default, because the SQL Server network library does
not enable the SO_REUSEADDR socket option, every time you open and close a
socket through the SQL Server network library on the client side, the socket
enters a TIME_WAIT state for four minutes. If you are rapidly opening and
closing SQL Server connections over TCP/IP with pooling disabled, you are
rapidly opening and closing TCP/IP sockets. In other words, each SQL Server
connection has one TCP/IP socket. If you rapidly open and close 4000 sockets
in less than four minutes, you will reach the default maximum setting for
client anonymous ports, and new socket connection attempts fail until the
existing set of TIME_WAIT sockets times out.
While you are not using SQL server, it is the same problem you are
having. What you can do is set the following value in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpTim
edWaitDelay
You can set the value to the number of seconds to wait before the socket
is usable again.
However, setting this can have detrimental effects. Is there a need to
open a few thousand client connections? Can it be done a different, and
more efficient way? Setting the above value is dangerous because it is
machine-wide.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com
AA said:This is making me crazy!!
Please, if some body can help me.
I'm testing a ver simple socket client.
In my test I just open and close a connection (in a loop) to my local IIS
server (port 80)
using System.Net.Sockets;
for (int I = 0; I < 5000; I++)
{
TcpClient myClient = new TcpClient();
try
{
myClient.Connect("127.0.0.1", 80)
}
catch (Exception ex) {MessangeBox.Show(ex.ToString()); }
myClient.Close()
} //End for
Everything go fine, thousands of connections are opened and closed until
this error appear....
[ System.Net.Sockets.SocketException: Only one usage of each socket address
(protocol/network address/port) is normally permitted ]
After this error, I execute the netstat -a command and the lines (below)
appear thousands of times, lines below are just a very little part of the
complete list.
TCP asusis-dsgn:3505 localhost:80 TIME_WAIT
TCP asusis-dsgn:3506 localhost:80 TIME_WAIT
TCP asusis-dsgn:3507 localhost:89 TIME_WAIT
TCP asusis-dsgn:3508 localhost:89 TIME_WAIT
TCP asusis-dsgn:3509 localhost:89 TIME_WAIT
TCP asusis-dsgn:3510 localhost:89 TIME_WAIT
TCP asusis-dsgn:3511 localhost:89 TIME_WAIT
TCP asusis-dsgn:3512 localhost:89 TIME_WAIT
TCP asusis-dsgn:3513 localhost:89 TIME_WAIT
TCP asusis-dsgn:3514 localhost:89 TIME_WAIT
TCP asusis-dsgn:3515 localhost:89 TIME_WAIT
TCP asusis-dsgn:3516 localhost:89 TIME_WAIT
TCP asusis-dsgn:3517 localhost:89 TIME_WAIT
TCP asusis-dsgn:3518 localhost:89 TIME_WAIT
TCP asusis-dsgn:3519 localhost:89 TIME_WAIT
TCP asusis-dsgn:3520 localhost:89 TIME_WAIT
TCP asusis-dsgn:3521 localhost:89 TIME_WAIT
TCP asusis-dsgn:3522 localhost:89 TIME_WAIT
TCP asusis-dsgn:3523 localhost:89 TIME_WAIT
TCP asusis-dsgn:3524 localhost:89 TIME_WAIT
TCP asusis-dsgn:3525 localhost:89 TIME_WAIT
TCP asusis-dsgn:3526 localhost:89 TIME_WAIT
TCP asusis-dsgn:3527 localhost:89 TIME_WAIT
I think that for some reason the .net framework is not really closing the
socket, so it still alive with the TIME_WAIT status
And after thousands of TIME_WAIT connections, the OS reject connections.
Pleaseeeeee help to solve it!!
Thanks