Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: Slightly rework main hub and gui lifecycle. #356

Merged
merged 1 commit into from
Sep 13, 2023

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Sep 12, 2023

This is rebased on #355.

This moves the creation of the context into the main code path, splits the creation logic for the hub and gui into independent funcs, and arranges for the main code path to create those instances and run them.

Since the pool struct is no longer necessary, both it and the associated newPool func are removed.

This approach is preferred because it provides the main code path with full control over the lifecycle of the context instead of stuffing it into a separate struct which makes it much harder to reason about and has ultimately led to the use of the cancel func deep in the innards of the hub which should not have that level of control since it is not the coordinator and thus does not have enough details to know when it's actually safe or even should be forcing a shutdown.

This commit does not address the latter part since it will require more in-depth changes to decouple it properly. However, this is a good start at reducing the overly-tight coupling of the lifecycle that exists as a result.

@davecgh davecgh force-pushed the main_rework_lifecycle branch 2 times, most recently from 9e8d19e to e91ad5f Compare September 12, 2023 10:12
return nil
}
if err := runHub(ctx, hub); err != nil {
// Ensure the GUI is signaled to shutdown.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite calling cancel here, the gui has no waitgroup (or any other mechanism of signalling that it has completed shutdown) so there is no guarantee that it will shutdown completely before the process terminates. Thats an existing problem though, and we can fix that in a later PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. My hope is that separating it out like this helps show the problem with the current design where it passes the cancel func down deep into the innards of something that does not control the overall process and thus shouldn't be able to just pull the rug out from everything as it's doing now.

Copy link
Member

@jholdstock jholdstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we expect this code to move again shortly, I've only given this PR a thorough read and not tested it very much. Will test more thoroughly once its closer to its final form.

This moves the creation of the context into the main code path, splits
the creation logic for the hub and gui into independent funcs, and
arranges for the main code path to create those instances and run them.

Since the pool struct is no longer necessary, both it and the associated
newPool func are removed.

This approach is preferred because it provides the main code path with
full control over the lifecycle of the context instead of stuffing it
into a separate struct which makes it much harder to reason about and
has ultimately led to the use of the cancel func deep in the innards of
the hub which should not have that level of control since it is not the
coordinator and thus does not have enough details to know when it's
actually safe or even should be forcing a shutdown.

This commit does not address the latter part since it will require more
in-depth changes to decouple it properly.  However, this is a good start
at reducing the overly-tight coupling of the lifecycle that exists as a
result.
@jholdstock jholdstock merged commit 26ee72b into decred:master Sep 13, 2023
2 checks passed
@davecgh davecgh deleted the main_rework_lifecycle branch September 13, 2023 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants