VCL client application waits up to 30 seconds when terminating

Hello, I've been experimenting with WebSocketServer and Client functionalities in a Windows-VCL application. Overall, everything seems fine, but I'm encountering a delay when terminating the client app. It appears that if the client was connected to the WebSocketServer, it attempts to disconnect and waits for a response from the server.

I've attempted to disable this behavior using fmxWebSocketClient.Options:=fmxWebSocketClient.Options + [twsoManualClose];, and also during destruction:

if fmxwebsocketclient.active then begin
	fmxwebsocketclient.Disconnect(false);
end;

However, these attempts haven't resolved the issue. My application still closes immediately when the client isn't actively used.

Hi,

Just by connecting to the server and closing the application we cannot see this behavior.

Regarding to this, do you mean during the form's OnDestroy event? That's not really necessary, the Disconnect is called automatically when the component is destroyed.

Can you put together a small sample that reproduces your issue so we can take a look?

I know, that the component calls Disconnect on destructor. Because it hangs than in the background I have tried to call it manually with (false) als parameter to speed up the "destroying" process.

There is nothing special in my code. I create the client-component in runtime and connect + send one message to the server with .Send
If I only create the component without calling connect or .Send the app terminates immediately.

We still cannot reproduce this.

procedure TForm5.Button2Click(Sender: TObject);
begin
  ws.Send('test');
end;

procedure TForm5.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ws.Free;
end;

procedure TForm5.FormCreate(Sender: TObject);
begin
  ws := TTMSFNCWebsocketClient.Create(Self);
  ws.HostName := 'localhost';
  ws.Port := 9999;
  ws.Connect;
end;

What are you doing differently?

This is my code:

		fmxWebsocketClient:=TTMSFNCWebsocketClient.Create;
		fmxwebsocketClient.hostname:='localhost';
		fmxwebsocketClient.port:=39800;
		fmxWebSocketClient.Options:=fmxWebSocketClient.Options +[twsoManualClose];
		fmxWebSocketClient.ConnectTimeout:=6000;
		fmxWebSocketClient.AutoCheckInterval:=30*1000;
		fmxWebSocketClient.AutoCheckMessages:=true;	
		fmxwebsocketclient.active:=true;

Ok, with this we could reproduce the issue now. We are investigating it.

1 Like

We were able to track this down and we applied a fix. The next version will contain the necessary changes.

1 Like