Commit 7d03f48
smc: defer subscription cleanup + strict arg validation across handlers
Six Copilot findings:
1. lantern-core/core.go's listenPeerConnectionEvents subscribed
to unbounded.ConnectionEvent and started a goroutine waiting
on ctx.Done to unsubscribe. If client.PeerConnectionEvents
returned an error while ctx was still live, the function
returned but the ctx-watcher goroutine + subscription leaked
for the rest of the process. Replaced with 'defer
unbSub.Unsubscribe()' so cleanup runs on both exit paths
(normal ctx cancel + unexpected stream exit).
2. iOS handler comment said the SmC setter helpers use a
'detached Task' but the implementation uses 'Task {}'. Updated
the comment to describe the actual choice — plain Task is
fine for the millisecond-range PatchSettings calls because
inheriting the current actor's executor is cheap; the
probeUPnP case is the one exception that uses Task.detached
because its M-SEARCH wait is multi-second.
3-5. macOS / iOS handlers had unsafe defaults on the SmC setters:
- setPeerProxyEnabled: defaulted enabled=false on missing arg
(would silently disable sharing on caller bugs)
- setPeerManualPort: defaulted port=0 on missing arg (would
silently clear the user's manual port override, since 0
has the real semantic of 'no manual port')
- setUnboundedEnabled: same Bool-defaults-to-false issue
(Copilot didn't flag this one but it has the identical
problem)
All four now route through requireArg, which surfaces a
FlutterError on missing/invalid argument shape instead of
defaulting silently.
6. Android setPeerManualPort defaulted port=0 the same way.
Switched the elvis '?: 0' to '?: error("Missing port")' to
match the SetPeerProxyEnabled pattern on Android.
Go build clean. The Swift / Kotlin changes are mechanical and
follow patterns already established in the same files
(requireArg / error()-on-missing).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 690494b commit 7d03f48
4 files changed
Lines changed: 40 additions & 24 deletions
File tree
- android/app/src/main/kotlin/org/getlantern/lantern/handler
- ios/Runner/Handlers
- lantern-core
- macos/Runner/Handlers
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1251 | 1251 | | |
1252 | 1252 | | |
1253 | 1253 | | |
1254 | | - | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
1255 | 1259 | | |
1256 | 1260 | | |
1257 | 1261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
273 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
274 | 276 | | |
275 | 277 | | |
276 | 278 | | |
| |||
279 | 281 | | |
280 | 282 | | |
281 | 283 | | |
282 | | - | |
283 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
284 | 290 | | |
285 | 291 | | |
286 | 292 | | |
| |||
289 | 295 | | |
290 | 296 | | |
291 | 297 | | |
292 | | - | |
293 | | - | |
| 298 | + | |
294 | 299 | | |
295 | 300 | | |
296 | 301 | | |
| |||
1173 | 1178 | | |
1174 | 1179 | | |
1175 | 1180 | | |
1176 | | - | |
1177 | | - | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
1178 | 1187 | | |
1179 | 1188 | | |
1180 | 1189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
433 | 434 | | |
434 | 435 | | |
435 | 436 | | |
| |||
442 | 443 | | |
443 | 444 | | |
444 | 445 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
| 446 | + | |
449 | 447 | | |
450 | 448 | | |
451 | 449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
255 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
256 | 258 | | |
257 | 259 | | |
258 | 260 | | |
259 | | - | |
260 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
261 | 267 | | |
262 | 268 | | |
263 | 269 | | |
| |||
266 | 272 | | |
267 | 273 | | |
268 | 274 | | |
269 | | - | |
270 | | - | |
| 275 | + | |
271 | 276 | | |
272 | 277 | | |
273 | 278 | | |
| |||
0 commit comments