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

feat: mark graph sessions as inactive so they don't show up in any UI #4285

Merged
merged 6 commits into from
Feb 14, 2022

Conversation

sgrove
Copy link
Contributor

@sgrove sgrove commented Feb 14, 2022

Summary

Fixes https://github.com/netlify/netlify-graph-project-planning/issues/44 (the cli portion)

We need to make sure we create sessions with the appropriate metadata, that we execute a heartbeat at server-specified intervals, and that on process exit we try our hardest to mark the session as inactive so that it can be removed from any UI list immediately, and also so that the server can GC sessions and associated resources.

Because the sessions may end up being GC'd, there's also logic to check if a session is still available at startup, and to create a new one without user intervention if not.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Make sure the status checks below are successful ✅

@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Feb 14, 2022
})
// eslint-disable-next-line promise/prefer-await-to-then,promise/always-return
.then(() => {
process.exit(1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a little bit confused by the presence of this line - it exits too rapidly, and prevents the signal handlers below from actually completing currently. I've left it in looking for some guidance, since I'm not sure why it's here.

@github-actions
Copy link

github-actions bot commented Feb 14, 2022

📊 Benchmark results

Comparing with 050bf90

Package size: 442 MB

(no change)

^  439 MB  439 MB  439 MB  439 MB  439 MB  438 MB  438 MB  438 MB  438 MB  438 MB  438 MB  438 MB  442 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@sgrove sgrove requested a review from erezrokah February 14, 2022 06:44
process.on(signal, async () => {
if (!cleanupStarted) {
// eslint-disable-next-line no-unused-vars
const cleanupFinished = await Promise.all(cleanupWork.map((cleanup) => cleanup()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we synchronise the cleanup work? Not sure if the promise in an process.on will be awaited propperly

Copy link
Contributor Author

@sgrove sgrove Feb 14, 2022

Choose a reason for hiding this comment

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

We cannot make it sync it, it's an IO call. I've tested locally that the promise is properly awaited though.

}
})
// eslint-disable-next-line promise/prefer-await-to-then
.then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid this promise chaining and move all this code under the first then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do we await the Promise.all inside of the first then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah, I see, it's an async function... on it!

})
// eslint-disable-next-line promise/prefer-await-to-then,promise/always-return
.then(() => {
process.exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar as before, can we move this under the first then?

@sgrove
Copy link
Contributor Author

sgrove commented Feb 14, 2022

@erezrokah cleaned up and centralized the process.exit logic.

This also fixes a bug that's probably been in the CLI for awhile where hitting Ctrl-C wouldn't show:

◈ Command was killed with SIGINT (User interruption with CTRL-C): yarn start. Shutting down Netlify Dev server

Because of the two separate process.exit invocations.

src/commands/dev/dev.js Outdated Show resolved Hide resolved
src/commands/dev/dev.js Outdated Show resolved Hide resolved
const fullSession = await OneGraphClient.fetchCliSession({ authToken: netlifyToken, appId, sessionId })
// @ts-ignore
const heartbeatIntervalms = fullSession.session.cliHeartbeatIntervalMs || defaultHeartbeatFrequency
nextMarkActiveHeartbeat = heartbeatIntervalms
Copy link
Contributor

Choose a reason for hiding this comment

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

[sand] The above two lines can be merged by removing the intermediary heartbeatIntervalms variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I specifically pulled it out so that it's obvious what the intention of that variable is via its name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright 👍

cleanupStarted = true
try {
// eslint-disable-next-line no-unused-vars
const cleanupFinished = await Promise.all(cleanupWork.map((cleanup) => cleanup()))
Copy link
Contributor

Choose a reason for hiding this comment

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

[sand] Since cleanupFinished is not used, should it be removed?

@sgrove
Copy link
Contributor Author

sgrove commented Feb 14, 2022

@ehmicky Ok, addressed PR comments

@sgrove sgrove added the automerge Add to Kodiak auto merge queue label Feb 14, 2022
@kodiakhq kodiakhq bot merged commit 2913759 into main Feb 14, 2022
@kodiakhq kodiakhq bot deleted the graph-cli-session-gc branch February 14, 2022 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Add to Kodiak auto merge queue type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants