Commit 8cb3713
peer: fix nil-pointer panic when UPnP discovery fails
Two changes to make the failure-on-discover path actually surface its
underlying error instead of crashing the IPC handler.
1. peer/peer.go's default cfg.NewForwarder wrapped
portforward.NewForwarder with a bare `return portforward.NewForwarder(ctx)`.
When discovery failed, that collapsed the `(*Forwarder)(nil), err`
pair into a typed-nil interface — `if fwd != nil` in the deferred
cleanup passed (the interface has a type), `fwd.UnmapPort(...)`
dispatched to a nil receiver, and `f.mu.Lock()` panicked. The
wrapper now returns a clean `nil, err` so the caller sees
ErrNoPortForwarding (or whatever the discoverer returned) and the
deferred cleanup short-circuits on the interface nil-check.
2. portforward.UnmapPort grew a defensive `if f == nil { return nil }`
at the top. Belt-and-suspenders for any future caller that lands
here through an interface and bypasses the inline nil-check —
teardown should be idempotent on a nil receiver, not a panic.
Reproduced live on macOS 26.x with `Share My Connection` toggled on
when UPnP discovery returned ErrNoPortForwarding; the http2 IPC
goroutine panicked instead of rolling back the toggle.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 61ff325 commit 8cb3713
2 files changed
Lines changed: 20 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
105 | 116 | | |
106 | 117 | | |
107 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
116 | 124 | | |
117 | 125 | | |
118 | 126 | | |
| |||
0 commit comments