Jump to content
gsachs

TCustomWSocketServer.Disconnect crashes

Recommended Posts

I have an application where a remote client is connected to WSocket Server.

On program close I want to disconnect all clients before the server is freed.

The DisconnectAll routine throws an access violation exception.

In the DisconnectAll there is a loop to disconnect all clients and the loop counter is a property of the TCustomWSocketServer.

It is read by the function GetClientCount which in turn returns the FClientList.Count property.

Should work normally but the ClientCount does not change., in my case it stays at 1.

The first loop is ok, the second  crashes.

 

In the Disconnect routine WClientClosed is called where the client is freed.

The comment there tells what should happen, but obviously it does not.

                { Calling Free will automatically remove client from list     }
                { because we installed a notification handler.                }
 

When I disconnect the clients one by one the client count exception is gone but in my FormClose routine I got another access violation exception.
This time at the line 'if operation = opRemove' below.

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCustomSslWSocket.Notification(AComponent: TComponent; operation: TOperation);
begin
    inherited Notification(AComponent, operation);
    if operation = opRemove then begin
        if AComponent = FSslContext then
            FSslContext := nil;
    end;
end;

 

Delphi 13 32Bit on W11, ICS 9.5 VCL only installed from Getit.

 

Does anybody have an idea to solve this ?

 

Share this post


Link to post

That notification function was added many years ago, no idea what purpose these notification handlers perform.  

 

I'd suggest just commenting out all but the Inherited line, doubt t will make any difference to functionality.   

 

I will investigate whether these notification handlers perform any useful purpose in ICS, but it will take a while, weeks.  

 

Angus

 

Share this post


Link to post
4 hours ago, Angus Robertson said:

That notification function was added many years ago, no idea what purpose these notification handlers perform. 

Angus,

Notification() is called when a child component is destroyed (Among other operations), allowing the owner component to cleanup what is necessary. For example, this is the mechanism by which a form gets notified when a component owned by the form is destroyed. The form may then remove the destroyed component from his control list.

Share this post


Link to post

The demo TCP server does not have this problem.

It is neither freed nor closed nor disconnected but the app works and closes without crash.
Maybe I'm doing much too much by first disconnecting, then closing, then freeing.

Is there a preferred way to close an application while the remote client is still running ?

Share this post


Link to post

When stopping a server, you close all listening sockets to stop new connections, then DisconnectAll for existing connections, wait for clients to fall to zero and free the server.  

 

Over the years, there have been problems closing connections.

 

With all my various servers, there is one FTP server that gives an error two or three times a week after uploading a large file, but this is out of many thousands of uploads on several FTP servers daily. I have CCTV cameras uploading motion capture images 24/7, one server says it's received 233GB of uploads in two weeks.

   

I really do need to look at whether notifications serve any useful purpose, but not until I've refreshed the V9.5 release with final updates, this week.  

 

Angus

 

 

 

 

Share this post


Link to post

I understand that finalizing the current version has priority.

Here is a wireshark file that shows whats happening on ethernet, I filtered just the interesting packets.

The remote machine on 10.10.10.123 was already running.

Then I started the server application in a VM while debugging.

I waited until it showed that the connection was established then I closed the app, which led to the exception.

 

Gerhard

 

 

IMS30_CS.pcapng

Share this post


Link to post

I don't doubt you are seeing a problem, but there must be something unusual about your implementation to cause it, otherwise this forum would be buried in others with the same problem, 

 

I'm only aware of a problem with one ICS sample, which I look into when I have the time.  

 

What happened when you removed the code I suggested. 

 

Angus

 

Share this post


Link to post

I've had a look at this problem, but without being able to reproduce it, there is little I can do, except add a lot of logging.  

 

If you explained more about what components you are using, how you are creating and using them, etc, there might be more clues. 

 

Ideally, a simple application that shows the problem for me to test.   

 

But if the problem goes away, suppressing the nil, I doubt there will be a problem.  There are other dependent components that don't set notifications, and the applications are OK. 

 

Angus

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×