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

Wait till all node_helper are started before finishing startup #2928

Merged
merged 3 commits into from
Oct 13, 2022

Conversation

rejas
Copy link
Collaborator

@rejas rejas commented Oct 3, 2022

In response to #2487 this implements a Promise.all for the node_helper start calls. Just a draft becuase I want to get feedback first....

@rejas rejas force-pushed the issue_2487 branch 2 times, most recently from 07e06da to 32b11e0 Compare October 4, 2022 12:57
Copy link
Contributor

@MikeBishop MikeBishop left a comment

Choose a reason for hiding this comment

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

Two pieces of feedback:

  • It might make sense to move the log line into the completion block, so that the message indicates when all modules have started rather than when all modules have been told to start. Or log in both places, to give some visibility into the time it takes for that to happen.
  • Contrary to my original suggestion, Promise.allSettled() (Node 12.9+) might be more appropriate so that an error doesn't cause it to complete prematurely.

@rejas rejas marked this pull request as ready for review October 4, 2022 15:26
@rejas
Copy link
Collaborator Author

rejas commented Oct 4, 2022

Thanks for the feedback @MikeBishop Now ready for real review ;-)

@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2022

Codecov Report

Merging #2928 (afdaeec) into develop (a328ce5) will increase coverage by 0.24%.
The diff coverage is 83.33%.

@@             Coverage Diff             @@
##           develop    #2928      +/-   ##
===========================================
+ Coverage    63.82%   64.06%   +0.24%     
===========================================
  Files            9        9              
  Lines          293      295       +2     
===========================================
+ Hits           187      189       +2     
  Misses         106      106              
Impacted Files Coverage Δ
js/app.js 60.33% <83.33%> (+0.66%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@rejas rejas linked an issue Oct 7, 2022 that may be closed by this pull request
Copy link
Collaborator

@sdetweil sdetweil left a comment

Choose a reason for hiding this comment

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

what about those that fail? are we expecting the module to alert the user somehow, and we say nothing? just thinking of debug

@rejas
Copy link
Collaborator Author

rejas commented Oct 7, 2022

not sure how many module developers use async here at all ....

@sdetweil
Copy link
Collaborator

sdetweil commented Oct 7, 2022

well, none in the start function.. cause it doesn't exist.. i use both promises and async where appropriate

@rejas
Copy link
Collaborator Author

rejas commented Oct 7, 2022

a module developer could use async anyway, even if it is not used in the prototype method (just like the OP does). might be interesting to mention it in the docs for developers...

@MikeBishop
Copy link
Contributor

FWIW, I wound up shipping mine using async anyway, and just putting the things that might take longer last. I haven't encountered any ill effects from my start-up routine completing a bit after the parent process thinks it did.

But @sdetweil makes an interesting point. In the current design, if a module throws an exception during start-up, does the server start-up fail entirely? If that's the desired behavior, then Promises.all() was the correct method to start with, and having it throw the first exception encountered and kill the program would provide a similar result.

@rejas
Copy link
Collaborator Author

rejas commented Oct 9, 2022

Im currently on a trip, so no real way for me to check the current behaviour.
I would hope though that in case of an error the other modules start too and a meaningful error is shown somewhere (console or notification)...

@rejas
Copy link
Collaborator Author

rejas commented Oct 12, 2022

In the current design, if a module throws an exception during start-up, does the server start-up fail entirely? If that's the desired behavior, then Promises.all() was the correct method to start with, and having it throw the first exception encountered and kill the program would provide a similar result.

Currently if a node_helper of a module throws an exception in the start method, all other node_helper after that dont get started due to:

"
[12.10.2022 22:49.47.556] [ERROR] Error: listen EADDRINUSE: address already in use 127.0.0.1:8080
"

As an example, use the default config and throw an exception in the newsfeed helper module. Calendar module wont start and show nothing...

With the changes here that will still happen. Why? Because the start method doesnt return a promise, and we have no try/catch anywhere in the startup sequence.

Do I like this behvior? No, since it confuses a user. If a module errors, only that module should error and not any other module that has nothing to do with it.

Two ways to fix it:

  1. Add a try catch somewhere around where the server starts and handle it gracefully
  2. Make the start method async (since it will then return a promise that can be handled with Promise.all...) and hope module developers change their method signature to use async too

Obviously 2) is a wishful thinking and would probably result in old modules that still work not being resilient. So I think 1) is the way to go. But since that doesnt have to happen here in this PR it can be done seperatly after this gets merged.

Comments?

@sdetweil
Copy link
Collaborator

yes, 2 is wonderful idea, but we have so many modules that are no longer maintained, this will never happen

so it must be option 1.

I personally hate that we have a fatal config error but continue to run with something else

@khassel
Copy link
Collaborator

khassel commented Oct 12, 2022

from my side this can be merged as it doesn't change the current state.

For a future PR: option 1 ...

@rejas
Copy link
Collaborator Author

rejas commented Oct 13, 2022

Created a ticket for the error handling improvement: #2944

@rejas rejas merged commit 7bbf8c1 into MagicMirrorOrg:develop Oct 13, 2022
@rejas rejas deleted the issue_2487 branch October 13, 2022 19:38
@rejas rejas mentioned this pull request Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async node_helper start()
5 participants