A bit late, but I have managed to replicate your findings.
The reason why the ensure is triggering is because you are creating the second Websocket in a scope of
Socket->GameThreadTick();
For example, if you have Websocket 1
and you are listening for messages using
WebSocket1->OnMessage().AddUObject(this, &ThisClass::HandleWebSocketMessage);
HandleWebSocketMessage
is executed via Socket->GameThreadTick();
thefore in the for loop.
So if you were to receive a message “Please open websocket 2” on the “Websocket 1” and create new WS in HandleWebSocketMessage
, it would be in the for loop iteration and you would add a second Websocket to the Sockets
array mid-iterating.
Since it’s possible to only add during the iteration, there is nothing technically wrong with it, but I have submitted a Pull Request to fix ensure
being triggered. https://github.com/EpicGames/UnrealEngine/pull/11934