HttpTimeout

HttpTimeout

#Overview

name: HttpTimeout

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of HttpTimeout is to set a time limit for HTTP requests within the Unreal Engine 5 networking system. It is primarily used to prevent HTTP requests from hanging indefinitely and to ensure that the game or application remains responsive even when network operations are slow or failing.

This setting variable is relied upon by several Unreal Engine subsystems and plugins:

  1. The core HTTP module in the Engine
  2. The IoStoreOnDemand experimental runtime module
  3. The AzureSpatialAnchorsForARCore plugin

The value of this variable is typically set in the engine configuration files (GEngineIni) and can be accessed or modified through the FHttpModule. It’s important to note that there are several related timeout variables, each controlling a different aspect of HTTP communication:

The HttpTimeout variable interacts with these other timeout variables, and they collectively define the behavior of HTTP requests in the engine.

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

  1. Setting the timeout too low may cause legitimate requests to fail, especially in poor network conditions.
  2. Setting the timeout too high may lead to unresponsive application behavior if a request hangs.
  3. The timeout value is used in different contexts (e.g., total request time, connection time, etc.) depending on the specific implementation.

Best practices when using this variable include:

  1. Set a reasonable default value in the engine configuration that balances responsiveness with allowing enough time for typical network operations.
  2. Allow for runtime configuration of the timeout value, especially for games that may be played in various network conditions.
  3. Implement proper error handling and retry logic for cases where requests time out.
  4. Monitor and log timeout occurrences to identify potential issues with network infrastructure or API endpoints.
  5. Consider using different timeout values for different types of requests (e.g., shorter for critical real-time data, longer for large file downloads).
  6. Ensure that the timeout value is not set lower than the minimum recommended value (10 seconds in the case of GDistributedEndpointTimeout).

By carefully managing the HttpTimeout and related variables, developers can ensure a robust and responsive networking experience in their Unreal Engine 5 projects.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/ConfigRedirects.ini:60, section: [HTTP]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/Runtime/AR/AzureSpatialAnchorsForARCore/Source/AzureSpatialAnchorsForARCore/ThirdParty/Include/AzureSpatialAnchorsNDK.h:519

Scope (from outer to inner):

file
namespace    Microsoft
namespace    Azure
namespace    SpatialAnchors

Source code excerpt:

         * The Http request timed out.
         */
        HttpTimeout = 20,
    };

    /**
     * Use the data category values to determine what data is returned in an AnchorLocateCriteria object.
     */
    enum class AnchorDataCategory : int32_t

#Loc: <Workspace>/Engine/Plugins/Runtime/AR/AzureSpatialAnchorsForARCore/Source/AzureSpatialAnchorsForARCore/ThirdParty/Include/AzureSpatialAnchorsNDK.h:656

Scope (from outer to inner):

file
namespace    Microsoft
namespace    Azure
namespace    SpatialAnchors

Source code excerpt:

         * The Http request timed out.
         */
        HttpTimeout = 97,
    };

    /**
     * Informs the application that a locate operation has completed.
     * 
     * @param sender The session that ran the locate operation.

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/IoStoreOnDemand/Private/DistributionEndpoints.cpp:38

Scope (from outer to inner):

file
namespace    UE::IO::IAS
function     FDistributionEndpoints::EResult FDistributionEndpoints::ResolveEndpoints

Source code excerpt:


	// The timeout is a cvar but should not be less than 10 seconds.
	const float HttpTimeout = FMath::Max(static_cast<float>(GDistributedEndpointTimeout), 10.0f);

	UE_LOG(LogIas, Log, TEXT("Resolving distributed endpoint '%s'"), *DistributionUrl);

	FHttpRequestPtr HttpRequest = FHttpModule::Get().CreateRequest();
	HttpRequest->SetTimeout(HttpTimeout);
	HttpRequest->SetURL(DistributionUrl);
	HttpRequest->SetVerb(TEXT("GET"));
	HttpRequest->SetHeader(TEXT("Accept"), TEXT("application/json"));
	HttpRequest->OnProcessRequestComplete().BindLambda(
		[this, &bHasResponse, &Event, &Result, &OutServiceUrls](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bOk)
		{

#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/HttpModule.cpp:51

Scope (from outer to inner):

file
function     void FHttpModule::UpdateConfigs

Source code excerpt:

void FHttpModule::UpdateConfigs()
{
	GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpTimeout"), HttpActivityTimeout, GEngineIni);
	GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpTotalTimeout"), HttpTotalTimeout, GEngineIni);
	GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpConnectionTimeout"), HttpConnectionTimeout, GEngineIni);
	GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpActivityTimeout"), HttpActivityTimeout, GEngineIni);
	GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpReceiveTimeout"), HttpReceiveTimeout, GEngineIni);
	GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpSendTimeout"), HttpSendTimeout, GEngineIni);
	GConfig->GetInt(TEXT("HTTP"), TEXT("HttpMaxConnectionsPerServer"), HttpMaxConnectionsPerServer, GEngineIni);

#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/NullHttp.cpp:173

Scope (from outer to inner):

file
function     void FNullHttpRequest::Tick

Source code excerpt:

	{
		ElapsedTime += DeltaSeconds;
		const float HttpTimeout = GetTimeout().Get(FHttpModule::Get().GetHttpTotalTimeout());
		if (HttpTimeout > 0 && ElapsedTime >= HttpTimeout)
		{
			UE_LOG(LogHttp, Warning, TEXT("Timeout processing Http request. %p"),
				this);

			FinishedRequest();
		}