Browse Source

Merge pull request #703 from meriadec/fix-zombie-processes

Fix zombie processes
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
b9da1346ee
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      package.json
  2. 3
      scripts/dist-dir.sh
  3. 2
      scripts/start.sh
  4. 37
      src/main/app.js
  5. 2
      src/main/bridge.js
  6. 32
      src/main/terminator.js

2
package.json

@ -8,7 +8,7 @@
"license": "MIT",
"scripts": {
"compile": "bash ./scripts/compile.sh",
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null",
"dist:dir": "bash ./scripts/dist-dir.sh",
"dist": "bash ./scripts/dist.sh",
"test": "jest",
"flow": "flow",

3
scripts/dist-dir.sh

@ -0,0 +1,3 @@
#/bin/bash
yarn compile && DEBUG=electron-builder electron-builder --dir -c.compression=store -c.mac.identity=null

2
scripts/start.sh

@ -1,5 +1,5 @@
#/bin/bash
concurrently --raw \
concurrently --raw --kill-others \
"cross-env NODE_ENV=development webpack-cli --mode development --watch --config webpack/internals.config.js" \
"cross-env NODE_ENV=development electron-webpack dev"

37
src/main/app.js

@ -7,12 +7,17 @@ import { MIN_HEIGHT, MIN_WIDTH } from 'config/constants'
import menu from 'main/menu'
import db from 'helpers/db'
import { setMainProcessPID, terminateAllTheThings } from './terminator'
setMainProcessPID(process.pid)
// necessary to prevent win from being garbage collected
let mainWindow = null
export const getMainWindow = () => mainWindow
let forceClose = false
// TODO put back OSX close behavior
// let forceClose = false
const { UPGRADE_EXTENSIONS, ELECTRON_WEBPACK_WDS_PORT, DEV_TOOLS, DEV_TOOLS_MODE } = process.env
@ -27,15 +32,16 @@ const getWindowPosition = (height, width, display = screen.getPrimaryDisplay())
}
}
const handleCloseWindow = w => e => {
if (!forceClose) {
e.preventDefault()
w.webContents.send('lock')
if (w !== null) {
w.hide()
}
}
}
// TODO put back OSX close behavior
// const handleCloseWindow = w => e => {
// if (!forceClose) {
// e.preventDefault()
// w.webContents.send('lock')
// if (w !== null) {
// w.hide()
// }
// }
// }
const getDefaultUrl = () =>
__DEV__ ? `http://localhost:${ELECTRON_WEBPACK_WDS_PORT || ''}` : `file://${__dirname}/index.html`
@ -107,7 +113,9 @@ function createMainWindow() {
window.loadURL(url)
window.on('close', handleCloseWindow(window))
// TODO put back OSX close behavior
// window.on('close', handleCloseWindow(window))
window.on('close', terminateAllTheThings)
window.on('ready-to-show', () => {
window.show()
@ -126,9 +134,10 @@ function createMainWindow() {
return window
}
app.on('before-quit', () => {
forceClose = true
})
// TODO put back OSX close behavior
// app.on('before-quit', () => {
// forceClose = true
// })
app.on('window-all-closed', () => {
// On macOS it is common for applications to stay open

2
src/main/bridge.js

@ -11,6 +11,7 @@ import sentry from 'sentry/node'
import user from 'helpers/user'
import setupAutoUpdater, { quitAndInstall } from './autoUpdate'
import { setInternalProcessPID } from './terminator'
import { getMainWindow } from './app'
@ -49,6 +50,7 @@ const bootInternalProcess = () => {
SENTRY_USER_ID: userId,
},
})
setInternalProcessPID(internalProcess.pid)
internalProcess.on('message', handleGlobalInternalMessage)
internalProcess.on('exit', handleExit)
}

32
src/main/terminator.js

@ -0,0 +1,32 @@
// @flow
// <((((((\\\
// / . }\
// ;--..--._|}
// (\ '--/\--' )
// DISCLAIMER \\ | '-' :'|
// This is a dirty hack \\ . -==- .-|
// \\ \.__.' \--._
// [\\ __.--| // _/'--.
// \ \\ .'-._ ('-----'/ __/ \
// \ \\ / __>| | '--. |
// \ \\ | \ | / / /
// \ '\ / \ | | _/ /
// \ \ \ | | / /
// \ \ \ /
let MAIN_PROCESS_PID: ?number = null
let INTERNAL_PROCESS_PID: ?number = null
function kill(processType, pid) {
console.log(`-> Killing ${processType} process ${pid}`) // eslint-disable-line no-console
process.kill(pid, 'SIGTERM')
}
exports.setMainProcessPID = (pid: number) => (MAIN_PROCESS_PID = pid)
exports.setInternalProcessPID = (pid: number) => (INTERNAL_PROCESS_PID = pid)
exports.terminateAllTheThings = () => {
if (INTERNAL_PROCESS_PID) kill('internal', INTERNAL_PROCESS_PID)
if (MAIN_PROCESS_PID) kill('main', MAIN_PROCESS_PID)
}
Loading…
Cancel
Save