See my comment in the other issue:
https://github.com/Warfley/LazWebsockets/issues/32It's currently a bug, which I had no time to fix.
But there are a few ways around this. First, when you use .Close, you don't need to call .StopReceiveMessageThread before, as close will kill the stream, which then also terminates the ReceiveMessageThread. It should be noted that closing the stream causes an Exception, which will be caught by the Receiver Thread. So when running normally, it will just silently terminate the thread, BUT, when running with the debugger in Lazarus, it will show a popup that an exception occured. Either just click it away (just click continue), or check the checkbox for Lazarus to ignore this exception in the future, as it is not an error, but simply the way how blocking stream operations are implemented
If you need to use StopReceiveMessageThread, without closing the stream (e.g. if you want to switch to manual message handling) you should simply send a "Ping" message afterwards to make sure a message will be returned which causes the receiving loop to stop.