Commit 21c01c8
fix(dhcp4): make the DHCPv4 client INIT path responsive to stop()
'pytcp stack start' could not be interrupted: a Ctrl-C ran the full
teardown, but the DHCPv4 client worker — parked in the RFC 2131 §4.4.1
startup desync 'time.sleep' (or a multi-second blocking recv in the
retransmission backoff) — missed the bounded 2.0 s join in
'Subsystem.stop()' and was left dangling. Because the worker was a
non-daemon thread, it then kept the interpreter alive AND ran the entire
acquisition (DISCOVER + 5 retransmits, ~2 min against a silent server),
so further Ctrl-Cs did nothing.
Two fixes:
- DHCPv4 client: the desync delay and the post-DECLINE backoff now wait
on the stop event instead of 'time.sleep' (interruptible; in sync
'fetch()' the event is never set, so they still behave as a sleep),
'_do_init_to_bound' aborts before opening a socket / before each
NAK-restart when stop is set, and '_recv_with_backoff' bails between
attempts. A daemon-mode stop() during INIT now halts immediately
without further wire traffic.
- Subsystem: spawn the worker as a daemon thread. The bounded join in
stop() still gives a graceful exit; the daemon flag is the safety net
so a worker stuck in a syscall is abandoned at interpreter exit rather
than wedging the process.
Tests-first. New TestDhcp4ClientStopResponsive pins: abort-before-socket
on stop, recv-backoff immediate bail, interruptible desync wait, and a
real-thread daemon stop() during the desync delay that does not leave
the worker dangling. New test__subsystem__worker_thread_is_daemon pins
the daemon flag. The three initial-delay tests and the decline-backoff
test are updated to assert the interruptible stop-event wait rather than
'time.sleep'.
Reference: RFC 2131 §4.4.1 (startup desynchronisation delay).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 8e4c209 commit 21c01c8
4 files changed
Lines changed: 212 additions & 21 deletions
File tree
- packages/pytcp/pytcp
- protocols/dhcp4
- runtime
- tests/unit
- protocols/dhcp4
- runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1351 | 1351 | | |
1352 | 1352 | | |
1353 | 1353 | | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
1354 | 1358 | | |
1355 | 1359 | | |
1356 | 1360 | | |
| |||
1363 | 1367 | | |
1364 | 1368 | | |
1365 | 1369 | | |
| 1370 | + | |
| 1371 | + | |
1366 | 1372 | | |
1367 | 1373 | | |
1368 | 1374 | | |
| |||
1484 | 1490 | | |
1485 | 1491 | | |
1486 | 1492 | | |
1487 | | - | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
1488 | 1496 | | |
1489 | 1497 | | |
1490 | 1498 | | |
| |||
1529 | 1537 | | |
1530 | 1538 | | |
1531 | 1539 | | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
1532 | 1546 | | |
1533 | 1547 | | |
1534 | 1548 | | |
| |||
1828 | 1842 | | |
1829 | 1843 | | |
1830 | 1844 | | |
1831 | | - | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
1832 | 1850 | | |
1833 | 1851 | | |
1834 | 1852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
113 | 119 | | |
114 | 120 | | |
115 | 121 | | |
| |||
Lines changed: 158 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
1156 | 1157 | | |
1157 | 1158 | | |
1158 | 1159 | | |
| 1160 | + | |
1159 | 1161 | | |
1160 | 1162 | | |
| 1163 | + | |
1161 | 1164 | | |
1162 | 1165 | | |
1163 | | - | |
| 1166 | + | |
1164 | 1167 | | |
1165 | 1168 | | |
1166 | | - | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
1167 | 1174 | | |
1168 | 1175 | | |
1169 | 1176 | | |
| |||
1179 | 1186 | | |
1180 | 1187 | | |
1181 | 1188 | | |
| 1189 | + | |
1182 | 1190 | | |
1183 | 1191 | | |
1184 | | - | |
| 1192 | + | |
1185 | 1193 | | |
1186 | | - | |
| 1194 | + | |
1187 | 1195 | | |
1188 | 1196 | | |
1189 | 1197 | | |
| |||
1193 | 1201 | | |
1194 | 1202 | | |
1195 | 1203 | | |
1196 | | - | |
1197 | | - | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
1198 | 1207 | | |
1199 | 1208 | | |
1200 | 1209 | | |
1201 | 1210 | | |
1202 | 1211 | | |
1203 | 1212 | | |
1204 | | - | |
1205 | | - | |
| 1213 | + | |
| 1214 | + | |
1206 | 1215 | | |
1207 | 1216 | | |
1208 | 1217 | | |
1209 | | - | |
1210 | | - | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
1211 | 1273 | | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
1212 | 1304 | | |
1213 | 1305 | | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
1214 | 1351 | | |
1215 | 1352 | | |
1216 | 1353 | | |
| |||
1415 | 1552 | | |
1416 | 1553 | | |
1417 | 1554 | | |
1418 | | - | |
1419 | | - | |
1420 | | - | |
1421 | | - | |
1422 | | - | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
1423 | 1561 | | |
1424 | | - | |
1425 | | - | |
1426 | | - | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
1427 | 1567 | | |
1428 | 1568 | | |
1429 | 1569 | | |
| |||
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
332 | 359 | | |
333 | 360 | | |
334 | 361 | | |
| |||
0 commit comments