Dart Home | PowerTCP Sockets for .NET | Custom Development | Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
Author | Forum: PowerTCP Sockets for .NET (Secure and Standard) Topic: Connections and TIME_WAIT |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted June 9, 2004 4:17 PM I have an application that uses the server component and take a lot of connections. Doing a netstat, I note that there are, often, over 300 connections, all in TIME_WAIT. Checking the server object's connections container, I get a count that's reasonably in agreement with netstat. These connections are all clients that connect, send a single line of text, get some text back, and then close. Sometimes they don't close on their own, but when the Connection method on the server finishes, I presume it closes the connection for me, right? So... am I right that it closes for me, or must I call Close() myself? And is there anything I can do to get these connections off the books, even if they're in TIME_WAIT? |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted June 9, 2004 4:25 PM I don't know of a way to stop that. I think the TCP-IP stack holds on to ports in certain situations in case the app that was using them wants to reuse them. In any event, if it says "TIME_WAIT", the connection has been closed. |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted June 9, 2004 6:41 PM Then why does the connections collection report that I have some 300 connections open? |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted June 9, 2004 6:53 PM You probably have 300 connections established and 300 connections in time wait. That would be my best guess anyway. |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted June 9, 2004 7:54 PM No, I have, looking at it right now, 3 active connections and 450+ or so in TIME_WAIT, and the connections collection says I have 465 items in the collection. I have 3 worker threads active, corresponding to the 3 active connections (I keep perfmon on threads and connections, incrementing the perfmon counter on entry and decrementing it on exit). The collection's Count property, however, definately says 465. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted June 9, 2004 8:12 PM Please describe the exact steps I need to take with our sample echo server to duplicate this. |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted June 9, 2004 8:22 PM That would be quite a test. Set it up, and then hit it with (looking at my current stats) 416,000 client requests from 45,000 different IP addresses. 271,000 of those requests should complete properly. 42,000 of them should presume that the input was bad, issue a tcp.Close() and return. The rest of them should have the connecting client fail to send anything, and simply "hang up" the connection immediately after establishing it. Alternatively, if there is any diagnostic code that I can put in my server (it's a WHOIS server, by the way - port 43 as per NICNAME), I'd be happy to do so. NB: I'm out of the office through the weekend (spending 4 days in California, lucky me :-)) |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted June 9, 2004 8:24 PM To be clear: In the last case, the client connects, and then the CLIENT immediately hangs up. My check to IsConnected fails, and I simply return. No tcp.Close(), since I know I've been hung up upon. |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted June 9, 2004 8:29 PM Well, obviously I can't set up a test like that. I think the best thing at this point would be for you to figure out a way to get the echo server to leave a connection in the collection after it closed. If you can find a way to do that I can begin looking into this. |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted June 9, 2004 8:32 PM If I put the echo server up so that every request that came in for our WHOIS server also went to the echo server, I could do that. But that still wouldn't do you much good. So what can I discern on my end from that collection that might help? Is there any state information in there? Can I keep any incoming information in the tag field that might evidence a trend? |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted June 9, 2004 11:23 PM Let's back up a second. Previously you said: "Sometimes they don't close on their own, but when the Connection method on the server finishes, I presume it closes the connection for me, right?" Actually, that's not always true. If you look at most of server samples, you'll notice that they are based on a known protocol where every anticipated request is handled. The connection.execute method goes into a blocking loop processing requests until either the server or client closes or requests a close. In the above case, yes , the connection would be closed when the event exited. However, if you look at the SecureProxy sample, you'll see that we keep the connection around after the event exits because we started an asynchronous process. Is it possible that you are doing something similar to the second example and are keeping connections around without realizing it? |
cambler From: Redmond, WA USA Posts: 102 Member Since: 04/14/03 |
posted June 14, 2004 11:52 AM I can't imagine how I would be keeping the connections around without actively doing something to do so. I have a read loop, then a database call, and then a write. They're all done synchronously, since each connection is on its own thread. In cases where I finish the send, I do a Close() on the tcp object before returning from the call. In cases where I note that the remote has hung up (the Connected property being false, for example), I don't issue a Close(), but just exit. I do, on average, about 200 connections per minute, and on average, 1 of them seems to stick around. Note, that when I say "stick around," I'm talking about only the numeric value of the Count property of the Connections collection. So the connection may not actually be around - it might just be the collection thinking it's around. So I'm wondering if there's something I can do to tell? Can I iterate on the connections collection and check anything that will give me an insight? (Sorry for the delay - I had to fly to California for the weekend for a family emergency) |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted June 14, 2004 11:57 AM I'll contact you via email to see if we can get anywhere. |
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
This site is powered by
![]() |