InitialConnectTimeout

InitialConnectTimeout

#Overview

name: InitialConnectTimeout

The value of this variable can be defined or overridden in .ini config files. 3 .ini config files referencing this setting variable.

It is referenced in 11 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of InitialConnectTimeout is to set the amount of time to wait for a new network connection to be established before destroying the connection. This variable is primarily used in the networking system of Unreal Engine 5.

The InitialConnectTimeout setting variable is relied upon by several Unreal Engine subsystems and modules, including:

  1. The core networking system (NetDriver)
  2. Online Subsystem Utils plugin
  3. Online Subsystem Oculus plugin
  4. Netcode Unit Test plugin

The value of this variable is typically set in the following ways:

  1. Through configuration files (as indicated by the UPROPERTY(Config) attribute in the UNetDriver class)
  2. Programmatically in various initialization functions (e.g., InitBase, InitClient, InitHost)
  3. Through URL options when initializing the network driver

This variable often interacts with other networking-related variables, such as:

  1. ConnectionTimeout: Used for established connections, typically shorter than InitialConnectTimeout
  2. BeaconConnectionInitialTimeout: Used specifically for beacon connections
  3. GNetRecreateSocketCooldown and GNetRecreateSocketTimeoutThreshold: Used in connection recreation logic

Developers should be aware of the following when using this variable:

  1. It affects the initial connection phase, not the maintenance of established connections
  2. It can be overridden in different contexts (e.g., for beacon connections or specific network drivers)
  3. Some systems may use this value to calculate other timeout-related durations

Best practices when using this variable include:

  1. Ensure it’s set to an appropriate value based on your game’s networking requirements and expected connection conditions
  2. Consider the relationship between InitialConnectTimeout and ConnectionTimeout
  3. Be aware of how different subsystems or plugins might override or modify this value
  4. Use configuration files or URL options to adjust the value for different deployment scenarios
  5. Monitor and log connection attempts that approach or exceed this timeout to identify potential networking issues

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:1631, section: [/Script/OnlineSubsystemUtils.IpNetDriver]

Location: <Workspace>/Engine/Config/BaseEngine.ini:2258, section: [/Script/SteamSockets.SteamSocketsNetDriver]

Location: <Workspace>/Engine/Plugins/Experimental/WebSocketNetworking/Config/BaseWebSocketNetDriver.ini:11, section: [/Script/WebSocketNetworking.WebSocketNetDriver]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/NetcodeUnitTest/NetcodeUnitTest/Source/NetcodeUnitTest/Private/MinimalClient.cpp:634

Scope (from outer to inner):

file
function     bool UMinimalClient::ConnectMinimalClient

Source code excerpt:

		// @todo #JohnB: Block voice channel?

		UnitNetDriver->InitialConnectTimeout = FMath::Max(UnitNetDriver->InitialConnectTimeout, (float)Timeout);
		UnitNetDriver->ConnectionTimeout = FMath::Max(UnitNetDriver->ConnectionTimeout, (float)Timeout);

#if !UE_BUILD_SHIPPING
		if (!(MinClientFlags & EMinClientFlags::SendRPCs) || !!(MinClientFlags & EMinClientFlags::DumpSendRPC))
		{
			UnitNetDriver->SendRPCDel.BindUObject(this, &UMinimalClient::NotifySendRPC);

#Loc: <Workspace>/Engine/Plugins/NetcodeUnitTest/NetcodeUnitTest/Source/NetcodeUnitTest/Private/NUTActor.cpp:460

Scope (from outer to inner):

file
function     void ANUTActor::HookNetDriver

Source code excerpt:

					CustomTimeout);

			TargetNetDriver->InitialConnectTimeout = static_cast<float>(CustomTimeout);
			TargetNetDriver->ConnectionTimeout = static_cast<float>(CustomTimeout);
		}
	}
}

bool ANUTActor::Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar)

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemOculus/Source/Private/OculusNetDriver.cpp:46

Scope (from outer to inner):

file
function     bool UOculusNetDriver::InitBase

Source code excerpt:

	}

	if (InitialConnectTimeout == 0.0)
	{
		UE_LOG(LogNet, Warning, TEXT("InitalConnectTimeout was set to %f"), InitialConnectTimeout);
		InitialConnectTimeout = 120.0;
	}

	if (ConnectionTimeout == 0.0)
	{
		UE_LOG(LogNet, Warning, TEXT("ConnectionTimeout was set to %f"), ConnectionTimeout);
		ConnectionTimeout = 120.0;

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpConnection.cpp:286

Scope (from outer to inner):

file
function     void UIpConnection::Tick

Source code excerpt:

			const double ElapsedTime = Driver->GetElapsedTime();
			const double LastRecreateSocketTime = IpDriver->GetLastRecreateSocketTime();
			const double InitialConnectMultiplier = (ElapsedTime < Driver->InitialConnectTimeout && LastRecreateSocketTime == 0.0) ? 2.0 : 1.0;
			const double RecreateCooldown = static_cast<double>(GNetRecreateSocketCooldown) * InitialConnectMultiplier;
			const double CooldownCompareTimeDiff = ElapsedTime - FMath::Max(GetConnectTime(), LastRecreateSocketTime);
			const double ThresholdCompareTimeDiff = ElapsedTime - FMath::Max(LastReceiveTime, GetLastRecvAckTime());

			if (CooldownCompareTimeDiff > RecreateCooldown && ThresholdCompareTimeDiff > GNetRecreateSocketTimeoutThreshold)
			{

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/IpConnection.cpp:626

Scope (from outer to inner):

file
function     float UIpConnection::GetTimeoutValue

Source code excerpt:

		if (IpDriver == nullptr || IpDriver->GetResolutionTimeoutValue() == 0.0f)
		{
			return Driver->InitialConnectTimeout;
		}

		return IpDriver->GetResolutionTimeoutValue();
	}

	return UNetConnection::GetTimeoutValue();

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/OnlineBeaconClient.cpp:194

Scope (from outer to inner):

file
function     bool AOnlineBeaconClient::InitClient

Source code excerpt:

						NetDriver->SetWorld(World);
						NetDriver->Notify = this;
						NetDriver->InitialConnectTimeout = BeaconConnectionInitialTimeout;
						NetDriver->ConnectionTimeout = BeaconConnectionTimeout;

						if (!bSentHandshake)
						{
							SendInitialJoin();
						}

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemUtils/Source/OnlineSubsystemUtils/Private/OnlineBeaconHost.cpp:108

Scope (from outer to inner):

file
function     bool AOnlineBeaconHost::InitHost

Source code excerpt:

				NetDriver->SetWorld(GetWorld());
				NetDriver->Notify = this;
				NetDriver->InitialConnectTimeout = BeaconConnectionInitialTimeout;
				NetDriver->ConnectionTimeout = BeaconConnectionTimeout;
				return true;
			}
			else
			{
				// error initializing the network stack...

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:894

Scope (from outer to inner):

file
class        class UNetDriver : public UObject, public FExec

Source code excerpt:

	/** Amount of time to wait for a new net connection to be established before destroying the connection */
	UPROPERTY(Config)
	float InitialConnectTimeout;

	/** 
	 * Amount of time to wait before considering an established connection timed out.  
	 * Typically shorter than the time to wait on a new connection because this connection
	 * should already have been setup and any interruption should be trapped quicker.
	 */

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/GameFramework/Actor.h:2674

Scope: file

Source code excerpt:

	 * Used by the net connection to determine if a net owning actor should switch to using the shortened timeout value
	 * 
	 * @return true to switch from InitialConnectTimeout to ConnectionTimeout values on the net driver
	 */
	virtual bool UseShortConnectTimeout() const { return false; }

	/**
	 * SerializeNewActor has just been called on the actor before network replication (server side)
	 * @param OutBunch Bunch containing serialized contents of actor prior to replication
	 */
	virtual void OnSerializeNewActor(class FOutBunch& OutBunch) {};

	/** 

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

Scope (from outer to inner):

file
function     float UNetConnection::GetTimeoutValue

Source code excerpt:

#endif

	float Timeout = Driver->InitialConnectTimeout;

	if ((GetConnectionState() != USOCK_Pending) && (bPendingDestroy || (OwningActor && OwningActor->UseShortConnectTimeout())))
	{
		const float ConnectionTimeout = Driver->ConnectionTimeout;

		// If the connection is pending destroy give it 2 seconds to try to finish sending any reliable packets

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:1488

Scope (from outer to inner):

file
function     bool UNetDriver::InitBase

Source code excerpt:

		if (ParsedValue != 0.0f)
		{
			InitialConnectTimeout = ParsedValue;
		}
	}
	if (const TCHAR* ConnectionTimeoutOverride = URL.GetOption(TEXT("ConnectionTimeout="), nullptr))
	{
		float ParsedValue;
		LexFromString(ParsedValue, ConnectionTimeoutOverride);