Commit 976e26c
authored
CC-6219: Implement setInactivityTimeout in ContainerClient (#5491)
* Implement setInactivityTimeout in ContainerClient
setInactivityTimeout allows a container to outlive its associated actor.
The current implementation tightly couples the lifetime of the container
client to the lifetime of the actor, so that the ContainerClient is
always destroyed whenever the actor is destroyed.
To fix this we make ContainerClient reference counted and provide a
reference to the actor. Whenever setInactivityTimeout is called we add a
reference to the client. If the actor shuts down, the remaining
reference keeps the container alive until the timeout expires. If
setInactivityTimeout was never called then there is no remaining
reference, and the container shuts down when the actor does.
We also implement the ability for an actor to reconnect to an already
running container when it restarts. We do this by maintaining a map of
containerId->ContainerClient in the ActorNamespace. This map does not
hold a reference to the ContainerClient: only actors and the inactivity
timeout promise hold references to ensure we do not leak resources by
holding a reference indefinitely. Whenever an actor starts it consults
the map to see if a ContainerClient already exists. If it doesn't we
create one and add it to the map.
In order to clear entries from the map when a ContainerClient is
destroyed we provide a callback function (`cleanupCallback`) to the
ContainerClient which is run when ContainerClient is destroyed.
* Add test for setInactivityTimeout1 parent 2b71448 commit 976e26c
File tree
4 files changed
+217
-62
lines changed- src/workerd/server
- tests/container-client
4 files changed
+217
-62
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
117 | | - | |
| 118 | + | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
120 | 126 | | |
121 | 127 | | |
122 | 128 | | |
| |||
250 | 256 | | |
251 | 257 | | |
252 | 258 | | |
253 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
254 | 264 | | |
255 | 265 | | |
256 | 266 | | |
| |||
427 | 437 | | |
428 | 438 | | |
429 | 439 | | |
430 | | - | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
431 | 453 | | |
432 | 454 | | |
433 | 455 | | |
| |||
444 | 466 | | |
445 | 467 | | |
446 | 468 | | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
447 | 473 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | 29 | | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
30 | | - | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
| |||
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
| 50 | + | |
| 51 | + | |
44 | 52 | | |
45 | 53 | | |
46 | 54 | | |
| |||
82 | 90 | | |
83 | 91 | | |
84 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
85 | 96 | | |
86 | 97 | | |
87 | 98 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2313 | 2313 | | |
2314 | 2314 | | |
2315 | 2315 | | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
2316 | 2321 | | |
2317 | 2322 | | |
2318 | 2323 | | |
| |||
2441 | 2446 | | |
2442 | 2447 | | |
2443 | 2448 | | |
| 2449 | + | |
2444 | 2450 | | |
2445 | 2451 | | |
2446 | 2452 | | |
| |||
2512 | 2518 | | |
2513 | 2519 | | |
2514 | 2520 | | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
2515 | 2524 | | |
2516 | 2525 | | |
2517 | 2526 | | |
| |||
2683 | 2692 | | |
2684 | 2693 | | |
2685 | 2694 | | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
2686 | 2700 | | |
2687 | 2701 | | |
2688 | 2702 | | |
| |||
2767 | 2781 | | |
2768 | 2782 | | |
2769 | 2783 | | |
2770 | | - | |
| 2784 | + | |
2771 | 2785 | | |
2772 | | - | |
2773 | | - | |
2774 | 2786 | | |
2775 | 2787 | | |
2776 | 2788 | | |
| |||
2782 | 2794 | | |
2783 | 2795 | | |
2784 | 2796 | | |
2785 | | - | |
2786 | | - | |
2787 | | - | |
2788 | | - | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
2789 | 2800 | | |
2790 | 2801 | | |
2791 | 2802 | | |
2792 | 2803 | | |
2793 | | - | |
| 2804 | + | |
2794 | 2805 | | |
2795 | 2806 | | |
2796 | 2807 | | |
| |||
2828 | 2839 | | |
2829 | 2840 | | |
2830 | 2841 | | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
| 2859 | + | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
| 2863 | + | |
| 2864 | + | |
| 2865 | + | |
| 2866 | + | |
2831 | 2867 | | |
2832 | 2868 | | |
2833 | 2869 | | |
| |||
2856 | 2892 | | |
2857 | 2893 | | |
2858 | 2894 | | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
2859 | 2901 | | |
2860 | 2902 | | |
2861 | 2903 | | |
| |||
0 commit comments