-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Replace Service's future impl by not-self-consuming method #6306
Conversation
It looks like @cecton signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
@@ -304,7 +302,6 @@ impl<G, E, F, L, U> TestNet<G, E, F, L, U> where | |||
let addr = node_config.network.listen_addresses.iter().next().unwrap().clone(); | |||
let service = SyncService::from(light(node_config).expect("Error creating test node service")); | |||
|
|||
executor.spawn(service.clone().map_err(|_| ())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I'm not sure why those tasks are spawn because the Future impl Service is just waiting indefinitely and stops if there is an essential task failing. But since this is spawn like a background process, nobody is doing anything with the result anyway. Will see if it breaks on the CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Service
used to properly own the tasks that it runs, and process them manually if no executor is available, rather than always spawning these tasks in the background.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That explains everything
I guess this is all debatable, but it was initially designed this way because good programming practices consist in stopping or killing stuff when destructors are being run, rather than having to call a |
In my opinion we have the choice between two approaches: either make the Having a |
I don't really have a clear opinion on this PR or how the |
🤔 it makes a lot more sense to me now. I guess in the current evolution of the Service it would be logical to make the Service more dumb. The alternative to this would be for the Service to own the tokio runtime so it can stop the tasks properly when dropping. But I suppose that is something we don't want as it would limit how substrate can be used. |
Fixed by ec2ab79 |
Problem it tries to fix
When the Service needs to be shutdown,
run_service_until_exit
does:telemetry
and thebase_path
from the ServiceThe reason why we do this in this particular order is because dropping the service will trigger the drop of the task_manager which will trigger the task's exit.
But this is annoying because it means we need to keep references on things that we don't want to be deleted during the tear down (telemetry and base_path).
A better approach would be to:
This would make sure that the things that must not be dropped before the tokio runtime are kept.
Proposed solution
I think the point 2. & 3. are not required but it makes more sense for the API.