Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Internet/Controls/TServerSocket    [ Add a report in this area ]  
Report #:  1145   Status: Closed
cannot terminate listening on TServerSocket (by setting Active to false or invoking Disconnect)
Project:  Delphi Build #:  Update Pack 2
Version:    6.0 Submitted By:   Pawel Suski
Report Type:  Basic functionality failure Date Reported:  5/6/2002 8:29:38 AM
Severity:    Serious / Highly visible problem Last Updated: 3/10/2005 6:07:07 PM
Platform:    All platforms Internal Tracking #:  
Resolution: Won't Do (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (13 Total Ratings)
3.38 out of 5
Total Votes: None
If you have a very busy server and there are many connections being opened frequently, you cannot terminate listening on TServerSocket (by setting Active to false or invoking Disconnect). It looks as it if cannot prevent new threads from being started. Also sometimes it throws Invalid Thread Handle (code no. 6).

Maybe trying to terminate TServerClientThread descendant threads AFTER (not BEFORE) closing listening socket would help.
Steps to Reproduce:

Joe White at 5/14/2002 11:21:45 AM -
So are you asking for a way to make the server stop listening (reject new connections), while keeping existing connections open?

Pawel Suski at 5/15/2002 3:10:56 AM -
No, I want to close all existing connections with all clients. The problem is that it is not very successful (you have to wait very long or get system exceptions) when clients are still requesting for new connections. TServer Socket is still accepting new connections after I set Active to false - it doesn't terminate listening thread but it wants to close all existing connections first. So after setting TServerSocket.Active to false we have a situation when the listening thread is accepting new connections (and creating new threads) and TServerSocket.Disconnect method is terminating these threads. Who will be the first? :)

Joe White at 5/15/2002 7:47:28 AM -
Ah, okay.  So currently it's closing the clients first and the listener second?  You have a point - that's really odd.  I wonder if there's really a race condition there, or if they manage to avoid it somehow.

Pawel Suski at 5/16/2002 1:44:20 AM -
Race condition is not actually the main problem. When TServerSocket is closing threads while the others are being launched it can sometimes throw weird exceptions. I got Invalid Thread Handle (code no. 6) or EPrivilegedInstruction (?). Then your program will hung up.

I will post a code which demostrates it when I have more time.

Server Response from: ETNACODE01