Skip to content

Fix Unreal heartbeat response parsing delays caused by incorrect completion and status checks#196

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-heartbeat-parsing-issue
Draft

Fix Unreal heartbeat response parsing delays caused by incorrect completion and status checks#196
Copilot wants to merge 3 commits intomainfrom
copilot/fix-heartbeat-parsing-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

What this PR does / why we need it:

ReceiveHeartbeat() has two bugs that cause heartbeat responses to be silently dropped or incorrectly processed, delaying session config population (sessionId, metadata, etc.) by up to ~10 minutes.

Bug 1: Content length check compares incompatible units

if (ContentString.Len() != Response->GetContentLength())

FString::Len() returns character count; GetContentLength() returns byte count. These diverge with non-ASCII UTF-8 or chunked transfer encoding (no Content-Length header), silently dropping valid responses. No other SDK (C#, C++, Java) performs this check.

Bug 2: Response code 0 passes the error check

if (Response->GetResponseCode() >= 300)  // 0 < 300 → passes

Connection failures yield response code 0 with an empty body. This reaches DecodeHeartbeatResponse(""), which fails JSON parsing and logs "Failed to parse heartbeat" every cycle.

Fix:

  • Replace the content length check with EHttpRequestStatus completion detection
  • Use break (not continue) for incomplete requests — the killIndex-based removal deletes entries 0..killIndex, so skipping an incomplete request at index N while processing index N+1 would incorrectly remove the incomplete one
  • Validate response codes are in 200–299 range
  • Guard against empty response bodies

Special notes for your reviewer:

Both the source copy (UnrealPlugin/Source/) and the TestingProject copy (UnrealPlugin/TestingProject/Plugins/) are updated identically. Unreal automation tests require the Editor and have no CI workflow, so changes were verified by code inspection and cross-referenced against C#/C++/Java SDK heartbeat handling.

If applicable:

  • this PR contains documentation
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility
Original prompt

This section details on the original issue you should resolve

<issue_title>Unreal Heart Beat Successful Parsing Takes Way Too Long</issue_title>
<issue_description>Describe the bug
Heart Beat Successful Parsing takes way too long, Almost 10 minutes, which means there is no sessionId Key in Config values for that duration and server Active delegate will take that long to be called, meaning Dedicated Server Build won't be able to get almost any Meta Data such as Match Id and so on.
FGSDKInternal::DecodeHeartbeatResponse keeps failing at if (!FJsonSerializer::Deserialize(Reader, HeartbeatResponseJson)) and logging "Failed to parse heartbeat"

Line 316 in GSDKInternal.cpp.

To Reproduce
-in Game Instance on Event Init Check Is Dedicated Server = True
-Set Default Server Host
-Register GSK Shutdown Delegate
-Register GSDK Health Check Delegate
-Register GSDK Maintenance V2 Delegate
-Register GSDK Server Active Delegate
-Register GSDK Ready for Players
-Call Ready for Players
-Get Match Id

Expected behavior
Heart Beat Parsing and filling up Config Values Should be way quicker than 10 minutes.

Screenshots
Screenshots of Game Instance

Image Image Image

Desktop (please complete the following information):

  • OS: Windows 11
  • Version 24H2 for x64-based Systems (KB5063878) (26100.4946)
  • Unreal Version : 4.27
  • Build Configuration : Development
  • Server Build Type Process
  • Added PF_StartupScript.ps1 to build.zip file so VM would install UE4PrereqSetup_x64 otherwise Build would be unhealthy (Can't upload the file but here's how it looks like)

PF_StartupScript.ps1

$root = $PSScriptRoot

$prereq = Join-Path $root 'Engine\Extras\Redist\en-us\UE4PrereqSetup_x64.exe'
if (Test-Path $prereq) {
Write-Host "Installing prerequisites from $prereq..."
Start-Process -FilePath $prereq -ArgumentList '/quiet','/norestart' -Wait
} else {
Write-Error "Prereq installer not found at $prereq"
exit 1
}

$serverExe = Join-Path $root 'HyperCycleRedux\Binaries\Win64\HyperCycleReduxServer.exe'
if (Test-Path $serverExe) {
Write-Host "Starting server $serverExe..."
Start-Process -FilePath $serverExe -ArgumentList '-log' -NoNewWindow
} else {
Write-Error "Server EXE not found at $serverExe"
exit 1
}

Additional context
GSDK Output Logs Retrieved from Dedicated server build

GSDK_output.txt
</issue_description>

<agent_instructions>Can you verify if this is an actual bug?</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 3, 2026 19:48
…ck with request status check and fix response code validation

The ReceiveHeartbeat() method had two bugs:

1. Content length check compared string character count with HTTP byte count,
   which fails for non-ASCII UTF-8 or chunked transfer encoding, silently
   dropping valid responses.

2. Response code check only rejected >= 300, allowing code 0 (connection
   failures) through to JSON parsing of empty bodies.

Fix: Use EHttpRequestStatus to properly detect completed requests, check
response code is in 200-299 range, and guard against empty response bodies.

Co-authored-by: dgkanatsios <8256138+dgkanatsios@users.noreply.github.com>
…ature queue removal

Co-authored-by: dgkanatsios <8256138+dgkanatsios@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Unreal Heart Beat successful parsing delay Fix Unreal heartbeat response parsing delays caused by incorrect completion and status checks Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unreal Heart Beat Successful Parsing Takes Way Too Long

2 participants