net.LogUnhandledFaults

net.LogUnhandledFaults

#Overview

name: net.LogUnhandledFaults

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 net.LogUnhandledFaults is to control the logging of unhandled network faults in Unreal Engine’s networking system. This setting variable is primarily used for debugging and monitoring network-related issues.

This setting variable is used by the Unreal Engine’s networking subsystem, specifically within the NetConnection module. It’s referenced in the Engine/Source/Runtime/Engine/Private/NetConnection.cpp file, which handles network connections.

The value of this variable is set using a TAutoConsoleVariable, which means it can be changed at runtime through console commands. The default value is 1, which means it will log unhandled faults once.

The associated variable CVarLogUnhandledFaults interacts directly with net.LogUnhandledFaults. They share the same value and purpose.

Developers must be aware that this variable has three possible states: 0 - Logging of unhandled faults is turned off 1 - Unhandled faults are logged once 2 - Unhandled faults are always logged

When using this variable, developers should consider the following best practices:

  1. Use it judiciously in production environments, as excessive logging can impact performance.
  2. Set it to 1 or 2 during development and testing phases to catch and diagnose network-related issues.
  3. Consider setting it to 0 in release builds to minimize performance impact, unless network fault monitoring is critical for the application.

Regarding the associated variable CVarLogUnhandledFaults:

The purpose of CVarLogUnhandledFaults is to provide a programmatic way to access and modify the net.LogUnhandledFaults setting within C++ code.

It’s used in the same networking subsystem as net.LogUnhandledFaults, specifically in the NetConnection module.

The value of CVarLogUnhandledFaults is set when it’s declared as a static TAutoConsoleVariable, mirroring the value of net.LogUnhandledFaults.

CVarLogUnhandledFaults interacts directly with net.LogUnhandledFaults, effectively serving as its C++ representation.

Developers should be aware that changes to CVarLogUnhandledFaults will affect net.LogUnhandledFaults and vice versa.

Best practices for using CVarLogUnhandledFaults include:

  1. Use GetValueOnAnyThread() to safely access its value from any thread.
  2. Consider the performance implications when frequently checking its value in performance-critical code paths.
  3. Use it in conjunction with FNetResult and FaultRecovery systems for comprehensive network fault handling and logging.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:101

Scope: file

Source code excerpt:

	TEXT("Enables congestion control module."));

static TAutoConsoleVariable<int32> CVarLogUnhandledFaults(TEXT("net.LogUnhandledFaults"), 1,
	TEXT("Whether or not to warn about unhandled net faults (could be deliberate, depending on implementation). 0 = off, 1 = log once, 2 = log always."));

static int32 GNetCloseTimingDebug = 0;

static FAutoConsoleVariableRef CVarCloseTimingDebug(TEXT("net.CloseTimingDebug"), GNetCloseTimingDebug,
	TEXT("Logs the last packet send/receive and TickFlush/TickDispatch times, on connection close - for debugging blocked send/recv paths."));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:101

Scope: file

Source code excerpt:

	TEXT("Enables congestion control module."));

static TAutoConsoleVariable<int32> CVarLogUnhandledFaults(TEXT("net.LogUnhandledFaults"), 1,
	TEXT("Whether or not to warn about unhandled net faults (could be deliberate, depending on implementation). 0 = off, 1 = log once, 2 = log always."));

static int32 GNetCloseTimingDebug = 0;

static FAutoConsoleVariableRef CVarCloseTimingDebug(TEXT("net.CloseTimingDebug"), GNetCloseTimingDebug,
	TEXT("Logs the last packet send/receive and TickFlush/TickDispatch times, on connection close - for debugging blocked send/recv paths."));

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:517

Scope (from outer to inner):

file
function     void UNetConnection::InitBase

Source code excerpt:

	FaultRecovery->InitDefaults((Driver != nullptr ? Driver->GetNetDriverDefinition().ToString() : TEXT("")), this);

	if (CVarLogUnhandledFaults.GetValueOnAnyThread() != 0)
	{
		FaultRecovery->FaultManager.SetUnhandledResultCallback([](FNetResult&& InResult)
			{
				static TArray<uint32> LoggedResults;

				const int32 LogVal = CVarLogUnhandledFaults.GetValueOnAnyThread();
				const bool bUniqueLog = LogVal == 1;
				const bool bAlwaysLog = LogVal == 2;
				const uint32 ResultHash = GetTypeHash(InResult);

				if (bAlwaysLog || (bUniqueLog && !LoggedResults.Contains(ResultHash)))
				{