Client Websocket disconnect issue

Summary

When disconnecting a TCustomWebsocketClient with a OnDisconnected event assigned application crash because FConnection was FreeAndNil before.

System Information

  • Operating system: Windows 11
  • Processor architecture: x86-64
  • Compiler version: 3.2.2 (With fcl-web and fcl-net from main branch)
  • Device: Computer

Steps to reproduce

  1. Create a TWebsocketClient
  2. Assign a disconnection event
  3. Connect to a websocket server
  4. Invoke disconnect from client

Example Project

What is the current bug behavior?

Application crashes with access violation at fpwebsocketclient.pp:464

What is the expected (correct) behavior?

Disconnection of TWebsocketClient with OnDisconnect triggering

Relevant logs and/or screenshots

Example code:

  FClient:=TWebsocketClient.Create(Self);
  FClient.OnDisconnect:=@DoDisconnect;
  [.. setting uri and connect...]
  FClient.Disconnect(false);

Just before crash: Capture_d_écran_2022-06-15_005354

Possible fixes

I've replace OnDisconnect(FConnection); with OnDisconnect(nil);

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information