-
Notifications
You must be signed in to change notification settings - Fork 109
Description
Wasmtime's host API today is that when a function is invoked it returns both the function's return value and TaskExit. The TaskExit value has a single method, block, which is intended to transitively wait for all subtasks spawned by the original root task. This structure is used in a few situations:
- When running a CLI component the main thread blocks for this method
- When running an arbitrary function via
--invokethe main thread waits on this before exiting - When processing HTTP requests in
wasmtime servethis is used as well
In discussions with @lukewagner and @dicej I've realized that Wasmtime's modeling of subtasks in this way is incorrect and needs to change. Effectively the TaskExit return value is going to need to be removed from Wasmtime because subtasks are tied to instances, not tasks themselves.
In doing this, however, it raises the question of what should be happening in all of these cases? For example at what point should wasi:cli/run "finish"? Is that the same answer as --invoke? Or is serve perhaps a bit different? I wanted to open this issue to write down some thoughts and have some possible discussion about this.
In the near-term what I plan to do is to add some sort of "wait for all tasks in this Store" method which will be used in all of these situations. That would mean, however, that a background task would keep the entire store alive and would keep Wasmtime from exiting. That's probably fine in the near-term but I don't think that this is a great long-term solution. I'm also not exactly sure what the solution might be and where it would lie, as the answer could be in WASI idioms or in the component model itself, unsure!