Add nil check for netstack in ping function and implement regression test

Fixes #439
This commit is contained in:
Owen
2026-08-28 09:20:00 -04:00
parent 21161dfbe5
commit e2139d0720
2 changed files with 15 additions and 0 deletions

View File

@@ -342,6 +342,17 @@ func TestParseTargetStringNetDialCompatibility(t *testing.T) {
}
}
// TestPingNilNetstackReturnsError is the regression guard for fosrl/newt#439:
// a still-running ping goroutine calling ping() with a nil *netstack.Net
// (after closeWgTunnel clears it during teardown/reconnect) must return an
// error instead of panicking with a nil pointer dereference.
func TestPingNilNetstackReturnsError(t *testing.T) {
_, err := ping(nil, "127.0.0.1", 100*time.Millisecond)
if err == nil {
t.Fatal("expected error when tnet is nil, got nil")
}
}
// TestShouldFireRecovery is the regression guard for the broken trigger gate
// that prevented data-plane recovery from ever firing under default settings
// (fosrl/newt#284, #310, pangolin#1004).

View File

@@ -47,6 +47,10 @@ func pingNative(dst string, timeout time.Duration) (time.Duration, error) {
}
func ping(tnet *netstack.Net, dst string, timeout time.Duration) (time.Duration, error) {
if tnet == nil {
return 0, fmt.Errorf("netstack not initialized")
}
socket, err := tnet.Dial("ping4", dst)
if err != nil {
return 0, fmt.Errorf("failed to create ICMP socket: %w", err)