MessageBus.UDP.InduceSocketError

MessageBus.UDP.InduceSocketError

#Overview

name: MessageBus.UDP.InduceSocketError

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of MessageBus.UDP.InduceSocketError is to simulate socket failures in the UDP messaging system for testing and debugging purposes. This setting variable is part of the network communication and error handling mechanism in Unreal Engine 5.

This setting variable is primarily used in the UdpMessaging plugin, which is part of the Unreal Engine’s messaging system. Specifically, it’s utilized in the UdpMessageProcessor component of the plugin.

The value of this variable is set through the console variable system in Unreal Engine. It’s initialized with a default value of 0, which means no induced errors by default.

MessageBus.UDP.InduceSocketError interacts with another console variable named MessageBus.UDP.ConnectionsToError. When MessageBus.UDP.InduceSocketError is set to a non-zero value, it will cause outbound socket connections to fail if the IP address matches one of the values specified in MessageBus.UDP.ConnectionsToError.

Developers must be aware that enabling this variable will intentionally cause network failures, which could impact the normal functioning of the UDP messaging system. It should only be used for testing and debugging purposes, not in production environments.

Best practices when using this variable include:

  1. Only enable it in controlled testing environments.
  2. Always reset it to 0 after testing to ensure normal network operation.
  3. Use it in conjunction with MessageBus.UDP.ConnectionsToError to target specific IP addresses for induced errors.
  4. Be prepared to handle and log the induced errors appropriately in your code.

Regarding the associated variable CVarFakeSocketError:

The purpose of CVarFakeSocketError is to provide programmatic access to the MessageBus.UDP.InduceSocketError setting within the C++ code of the UdpMessageProcessor.

This variable is used directly in the UdpMessaging plugin, specifically in the UdpMessageProcessor component.

The value of CVarFakeSocketError is set automatically by the console variable system when MessageBus.UDP.InduceSocketError is modified.

CVarFakeSocketError interacts with the ShouldErrorOnConnection function, which checks its value to determine whether a connection should intentionally fail.

Developers should be aware that modifying CVarFakeSocketError directly in code will have the same effect as changing MessageBus.UDP.InduceSocketError through the console.

Best practices for using CVarFakeSocketError include:

  1. Avoid modifying it directly in code unless absolutely necessary.
  2. Use it for reading the current state of MessageBus.UDP.InduceSocketError in your C++ code.
  3. Remember that changes to this variable will affect the entire UDP messaging system, so use it cautiously.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Messaging/UdpMessaging/Source/UdpMessaging/Private/Transport/UdpMessageProcessor.cpp:26

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarFakeSocketError(
	TEXT("MessageBus.UDP.InduceSocketError"),
	0,
	TEXT("This CVar can be used to induce a socket failure on outbound communication.\n")
	TEXT("Any non zero value will force the output socket connection to fail if the IP address matches\n")
	TEXT("one of the values in MessageBus.UDP.ConnectionsToError. The list can be cleared by invoking\n")
	TEXT("MessageBus.UDP.ClearDenyList."),
	ECVF_Default

#Associated Variable and Callsites

This variable is associated with another variable named CVarFakeSocketError. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Plugins/Messaging/UdpMessaging/Source/UdpMessaging/Private/Transport/UdpMessageProcessor.cpp:25

Scope: file

Source code excerpt:

const int32 FUdpMessageProcessor::DeadHelloIntervals = 5;

TAutoConsoleVariable<int32> CVarFakeSocketError(
	TEXT("MessageBus.UDP.InduceSocketError"),
	0,
	TEXT("This CVar can be used to induce a socket failure on outbound communication.\n")
	TEXT("Any non zero value will force the output socket connection to fail if the IP address matches\n")
	TEXT("one of the values in MessageBus.UDP.ConnectionsToError. The list can be cleared by invoking\n")
	TEXT("MessageBus.UDP.ClearDenyList."),

#Loc: <Workspace>/Engine/Plugins/Messaging/UdpMessaging/Source/UdpMessaging/Private/Transport/UdpMessageProcessor.cpp:54

Scope (from outer to inner):

file
namespace    UE::Private::MessageProcessor
function     bool ShouldErrorOnConnection

Source code excerpt:

bool ShouldErrorOnConnection(const FIPv4Endpoint& InEndpoint)
{
	if (CVarFakeSocketError.GetValueOnAnyThread() == 0)
	{
		return false;
	}

	const FString ConnectionsToErrorString = CVarConnectionsToError.GetValueOnAnyThread();
	TArray<FString> EndpointStrings;