-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix: Ensure that file watchers are closed before Electron exits #22606
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
Conversation
…will be a disaster currently.
…tbiethman/UNIFY-1816-prototype # Conflicts: # circle.yml # packages/data-context/src/actions/ProjectActions.ts # packages/data-context/src/sources/GitDataSource.ts
…tbiethman/UNIFY-1816-prototype
Thanks for taking the time to open a PR!
|
@@ -429,7 +429,11 @@ export class DataContext { | |||
} | |||
|
|||
async destroy () { | |||
const destroy = util.promisify(this.coreData.servers.gqlServer?.destroy || (() => {})) |
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.
util.promisify(() => {})
This noop didn't work because it never resolved. We replaced it with () => Promise.resolve()
@@ -170,6 +173,36 @@ export = { | |||
makeGraphQLServer(), | |||
]) | |||
|
|||
const clearCtxAndQuit = async () => { |
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.
This file contains the bulk of the changes. Most of the other changes in this diff are related to await
ing function calls that are now async
…o/cypress into tbiethman/UNIFY-1816-prototype
Test summaryRun details
View run in Cypress Dashboard ➡️ Flakiness
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
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.
Sorry it took so long to review, I missed this one. I left a few tiny comments, once those are good let's ship it.
@@ -170,6 +173,36 @@ export = { | |||
makeGraphQLServer(), | |||
]) | |||
|
|||
const clearCtxAndQuit = async () => { | |||
try { | |||
await clearCtx() |
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.
There is a comment saying we should not call this in runtime: https://github.com/cypress-io/cypress/pull/22606/files#diff-1827debd8088884005aba0e14a94e1e6815ceb1ad567db970f9f327d9feb7c9dR27
If we are doing this, I think we need to change the comment?
Also, maybe a comment here explaining why we clearCtx before closing? Could link to the relevant GH issue
packages/server/lib/modes/run.js
Outdated
@@ -1650,6 +1650,7 @@ module.exports = { | |||
async run (options, loading = Promise.resolve()) { | |||
if (require('../util/electron-app').isRunningAsElectronProcess({ debug })) { | |||
const app = require('electron').app | |||
const { clearCtx } = require('@packages/data-context') |
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.
Was there a reason to inline this require instead of putting it at the top?
Will make an eventual ESM convert easier.
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 existing data-context require used to be at root but was changed with https://github.com/cypress-io/cypress/pull/20932/files#diff-58fd4a8e28c13b52b19c42346eade66ed1de5a8b139541dff4e94fef42c3c701R666-R667. I assume due to how the run script is getting loaded?
Regardless, I am going to revert the changes to this file for run mode. I don't think the process.exit handler is deterministic here, just like it wasn't before in the ProjectLifecycleManager. And because we don't initialize watchers in run mode, the teardown isn't necessary prior to exit.
…tbiethman/UNIFY-1816-prototype # Conflicts: # packages/data-context/src/data/ProjectLifecycleManager.ts
@astone123 @lmiller1990 I have addressed the current PR feedback and pushed a few new commits. The biggest change was addressing the TODO regarding closing the file watchers when the ProjectConfigManager errored. I was able to keep closing these by untangling some of the circular logic between the ProjectLifecycleManager and the ProjectConfigManager. You can that see in the diff. Doing it this way allows us to keep the lifecycle manager error handling functionally equivalent while allowing for async handling within the config manager itself. I'm happy to answer more questions around that, otherwise I think we're good to go for a final review. |
destroy () { | ||
this.resetInternalState() | ||
// @ts-ignore | ||
process.removeListener('exit', this.onProcessExit) |
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.
Do we not need to remove this anymore?
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.
Nope, we no longer add the listener in the first place.
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.
My comments are addressed. Just need CI to pass and we can merge?
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Closes #22026
This PR uses a
will-quit
hook for Electron to ensure that we close all of the DataContext file watchers before the application exits.See the related issue for more info.
User facing changelog
Testing: