Commit 736518e
committed
Add graceful shutdown to
This commit fixes the spurious CI failure found [here][fail]. The
problem here is that the infrastructure for testing `wasmtime serve` was
not properly waiting for all output in `finish`. There's some
infrastructure in the tests for spawning a subprocess and managing it,
but prior to this commit there was no way to shut down the server
gracefully and thus read all pending output from the child tasks.
The specific problem is that a specific error message was expected in
the logs after a request had been processed, but the `finish` method
wasn't reading the message. The reason for this is that `finish` had to
resort to `kill -9` on the child process as there was no other means of
shutting it down. This meant that the print, which happened after
request completion, might be killed and never happen.
The solution ended up in this commit is to (a) add a `--shutdown-addr`
CLI flag to `wasmtime serve` and (b) beef up handling of graceful
shutdown. Previously ctrl-c was used to exit the server but it didn't do
anything but drop all in-progress work. Instead graceful shutdown is now
handled by breaking out of the `accept` loop and then waiting for all
child tasks to complete, meaning that no http requests once received are
cancelled. In addition to ctrl-c the `--shutdown-addr` is used to listen
for a TCP connection which is a second means of cancellation. The reason
for this is that sending ctrl-c to a process is not nearly as trivial on
Windows as it is on Unix, so I didn't want to deal with all the console
bits necessary to get that aligned.
[fail]: https://github.com/bytecodealliance/wasmtime/actions/runs/13833291117/job/38702374924?pr=10390wasmtime serve, fix flaky CI1 parent 9da52ed commit 736518e
2 files changed
+161
-52
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
91 | 99 | | |
92 | 100 | | |
93 | | - | |
| 101 | + | |
94 | 102 | | |
95 | 103 | | |
96 | 104 | | |
| |||
134 | 142 | | |
135 | 143 | | |
136 | 144 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 145 | + | |
148 | 146 | | |
149 | 147 | | |
150 | 148 | | |
| |||
371 | 369 | | |
372 | 370 | | |
373 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
374 | 396 | | |
375 | 397 | | |
376 | 398 | | |
| |||
403 | 425 | | |
404 | 426 | | |
405 | 427 | | |
406 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
407 | 435 | | |
408 | 436 | | |
| 437 | + | |
409 | 438 | | |
410 | 439 | | |
411 | 440 | | |
| |||
417 | 446 | | |
418 | 447 | | |
419 | 448 | | |
| 449 | + | |
420 | 450 | | |
421 | 451 | | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
422 | 518 | | |
423 | 519 | | |
424 | 520 | | |
| |||
533 | 629 | | |
534 | 630 | | |
535 | 631 | | |
536 | | - | |
| 632 | + | |
537 | 633 | | |
538 | 634 | | |
539 | 635 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1530 | 1530 | | |
1531 | 1531 | | |
1532 | 1532 | | |
| 1533 | + | |
1533 | 1534 | | |
1534 | 1535 | | |
1535 | 1536 | | |
| |||
1548 | 1549 | | |
1549 | 1550 | | |
1550 | 1551 | | |
| 1552 | + | |
1551 | 1553 | | |
1552 | 1554 | | |
1553 | 1555 | | |
1554 | 1556 | | |
1555 | 1557 | | |
1556 | | - | |
1557 | | - | |
1558 | | - | |
1559 | | - | |
1560 | | - | |
1561 | | - | |
1562 | | - | |
1563 | | - | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
1564 | 1563 | | |
1565 | 1564 | | |
1566 | | - | |
1567 | | - | |
1568 | | - | |
1569 | | - | |
1570 | | - | |
1571 | | - | |
1572 | | - | |
1573 | | - | |
1574 | | - | |
1575 | | - | |
1576 | | - | |
1577 | | - | |
1578 | | - | |
1579 | | - | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
1580 | 1581 | | |
1581 | | - | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
1582 | 1590 | | |
1583 | 1591 | | |
1584 | 1592 | | |
1585 | | - | |
| 1593 | + | |
1586 | 1594 | | |
1587 | | - | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
1588 | 1603 | | |
1589 | 1604 | | |
1590 | 1605 | | |
1591 | 1606 | | |
1592 | 1607 | | |
1593 | 1608 | | |
1594 | | - | |
1595 | | - | |
1596 | | - | |
1597 | | - | |
1598 | | - | |
1599 | | - | |
1600 | | - | |
1601 | | - | |
1602 | | - | |
1603 | | - | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
1604 | 1617 | | |
1605 | | - | |
| 1618 | + | |
1606 | 1619 | | |
1607 | 1620 | | |
1608 | 1621 | | |
| |||
0 commit comments