-
Notifications
You must be signed in to change notification settings - Fork 154
Conversation
Codecov Report
@@ Coverage Diff @@
## master #367 +/- ##
==========================================
+ Coverage 37.72% 39.18% +1.46%
==========================================
Files 157 157
Lines 3494 3504 +10
Branches 440 441 +1
==========================================
+ Hits 1318 1373 +55
+ Misses 1900 1860 -40
+ Partials 276 271 -5
|
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.
Unfortunately this is still not killing the servers properly for me on Mac. I'm testing with both X button and "Quit Guppy" in the menu bar but it's not killing the server on 3001.
I dug into it and maybe found the reason? Not too sure, but this discrepancy is interesting.
When we are toggling on the dev server we are sending along the PID to the main process via the following (in task.saga.js):
yield call([ipcRenderer, ipcRenderer.send], 'addProcessId', child.pid);
I console logged this PID when we receive it in electron.js like so (plus the processIds array):
ipcMainHandle.on('addProcessId', (event, processId) => {
processIds.push(processId);
notify('addProcessId', processIds);
console.log('PID from dev server: ', processId);
console.log('processIds array: ', processIds);
});
As you can see in the following screenshot, the PID logged doesn't match the PID of the actual server that's open on 3001. Not really sure where it's getting this different PID.
package.json
Outdated
@@ -28,7 +28,7 @@ | |||
"dist:all": "cross-env GENERATE_SOURCEMAP=false npm run build && electron-builder -mwl -c.extraMetadata.main=build/electron.js", | |||
"publish": "yarn dist --publish always", | |||
"publish:all": "yarn dist:all --publish always", | |||
"test": "node scripts/test.js --maxWorkers=2 --env=node", | |||
"test": "node scripts/test.js --maxWorkers=2 --env=node --verbose=false", |
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 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.
Oh OK, I used it to enable console.log
for debugging. I haven't noticed that this behaviour is changed. I'll remove it.
OK, that's weird maybe it's a process id of a child. Can you please check the pids when taskkill is called? If it's the same we need to figure out which id it is storing - not sure why this is not working on Mac. |
@melanieseltzer the following issue is interesting and you could try the following to find the cause of the wrong PID:
|
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.
Very nice, clean tests, just a few small points of feedback. I'm going to investigate further on Mac and attempt to replicate some of the behavior @melanieseltzer and others have noticed, I'll report back if I find anything.
EDIT 2: Nevermind, the parent process ID is the pid of EDIT 3: Looks like EDIT 4: Hooray! Converting -- Alright, so here's some potential insight. Launch Guppy, start a new project
Electron sees the pid @melanieseltzer can you replicate this behavior? Use EDIT: Stopping the dev server prints the following:
which seems to support the idea that the wrong pid is being passed around. |
@melanieseltzer can you double-check that this now works for you on Mac? @AWolf81 feel free to leave any review comments on my pushed code, I can't request your review since this is your PR. EDIT: Forgot to update the tests, I'll get that fixed tonight unless someone else beats me to it. EDIT 2: Done. |
Tested with both options (app quit from menu bar and X button) and processes are successfully getting killed for me 🎉 Nice one, @superhawk610! |
const killAllRunningProcesses = async () => { | ||
try { | ||
await Promise.all( | ||
processIds.map(processId => { |
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.
Curious why change from forEach
to map
here?
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 is a strange pattern if you haven't seen it before. Promise.all(promiseArr)
waits for every Promise
in promiseArr
to resolve before resolving itself. It should make more sense if I write it out without using .map
notation:
const mapCallback = processId => {
processIds = processIds.filter(id => id !== processId);
return killProcessId(processId);
};
// processIds = [1, 2, 3];
await Promise.all([
mapCallback(1),
mapCallback(2),
mapCallback(3),
]);
killProcessId
returns a Promise
, and we need to get that promise into the array that Promise.all()
is using. This essentially boils down to:
await Promise.all([
killProcessId(1),
killProcessId(2),
killProcessId(3),
]);
Does that help?
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.
Nice, I knew it was due to needing a return value but for some reason I wasn't connecting the dots as to what exactly it was returning 😆 Clever.
Related Issue:
#364 & #344
Summary:
spawnSync
so taskkill is executed before closing the app.event.preventDefault
from ipc callback as I think it's not available & not needed. IpcMain event got just two key - see the docs hereKilling tested on Ubuntu 18.0.4 (64bit) & Windows 10 Pro (64bit).
Test steps to verify task killing
yarn start
(executing the binary should do the same)netstat -aon | find "3001"
orlsof -i :3001
on Mac/Linux)Discussion
spawnSync
has an impact on performance? How can we check this? Maybe starting multiple devServers and check app close duration?