mirror of
https://github.com/fosrl/newt.git
synced 2026-07-16 03:46:25 -05:00
[PR #413] fix(connect): decode registration into a fresh WgData to prevent stale hcStatus on reconnect #8993
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/fosrl/newt/pull/413
Author: @lafoush
Created: 7/14/2026
Status: 🔄 Open
Base:
main← Head:fix/reconnect-stale-hcstatus📝 Commits (1)
4e35596fix(connect): decode registration into a fresh WgData to prevent stale hcStatus📊 Changes
2 files changed (+84 additions, -1 deletions)
View changed files
📝
newt/connect.go(+8 -1)➕
newt/wgdata_reconnect_test.go(+76 -0)📄 Description
Problem
A resource with a health check can be reported permanently Unhealthy after a reconnect, even though it responds correctly, until newt is restarted. It's intermittent and only happens on reconnect (never on a clean boot).
Root cause
handleConnectdecodes thenewt/wg/connectregistration payload into the persistentn.wgData:Go's
encoding/jsonmerges a JSON array into an existing non-empty slice element-by-element, by position, and a JSONnullis a no-op for a non-pointer field such ashealthcheck.Config.Status(hcStatus, anint).n.wgDatais reused across reconnects, so:wgData.HealthCheckTargets, e.g. slot 0 ={id:47, hcStatus:401}, slot 1 ={id:5, hcStatus:null}.ORDER BY), e.g.[{id:5, hcStatus:null}, {id:47, hcStatus:401}].id:5,hcStatus:null) into old-slot-0 (id:47,hcStatus:401).idis overwritten to 5, but thenullhcStatusdoes not overwrite the retained401.401. Its check (GET /manifest.json→200) fails forever withunexpected status code: 200 (expected: 401).handleSyncis unaffected because it decodes into a fresh localSyncData. A clean boot is unaffected becausewgDatastarts empty. This matches the observed profile exactly: reconnect-only, intermittent (needs a row reorder), self-heals on restart.Fix
Decode the registration payload into a fresh
WgDataand assign it on success, so no state is ever carried over from a previous connection:n.wgDatais written nowhere else, so a wholesale replace is safe.Test
Adds
newt/wgdata_reconnect_test.go, which pins both halves:WgDatareproduces the stale401inheritance;WgData(whathandleConnectnow does) keeps target 5 free of target 47's expected code.go build ./...,go vet ./newt/, and the full./newt/+./healthcheck/suites pass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.