Skip to content

Commit

Permalink
Fix Backend Dying (enso-org/ide#1428)
Browse files Browse the repository at this point in the history
Original commit: enso-org/ide@63917f4
  • Loading branch information
mwu-tow authored Apr 2, 2021
1 parent 43e65a8 commit ba392ea
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ide/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
when the mouse events are passed to the visualization.
- [Fixed an issue when projects containing certain language constructs failed to
load.][1413]
- [Fixed a case where IDE could lose connection to the backend after some
time.][1428]

#### EnsoGL (rendering engine)

Expand Down Expand Up @@ -147,6 +149,7 @@ you can find their release notes
[1412]: https://github.com/enso-org/ide/pull/1412
[1419]: https://github.com/enso-org/ide/pull/1419
[1413]: https://github.com/enso-org/ide/pull/1413
[1428]: https://github.com/enso-org/ide/pull/1428

<br/>

Expand Down
47 changes: 43 additions & 4 deletions ide/src/js/lib/client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,28 +332,67 @@ Electron.app.on('web-contents-created', (event,contents) => {
// === Project Manager ===
// =======================

async function withBackend(opts) {
function projectManagerPath() {
let binPath = args['backend-path']
if (!binPath) {
binPath = paths.get_project_manager_path(resources)
}
let binExists = fss.existsSync(binPath)
assert(binExists, `Could not find the project manager binary at ${binPath}.`)
return binPath
}

/**
* Executes the Project Manager with given arguments.
*
* Note that this function captures all the Project Manager output into a fixed
* size buffer. If too much output is produced, it will fail and Project
* Manager process will prematurely close.
*
* @param {string[]} args Project Manager command line arguments.
* @returns Promise with captured standard output and error contents.
*/
async function execProjectManager(args) {
let binPath = projectManagerPath()
return await execFile(binPath,args).catch(function(err) {throw err})
}

let out = await execFile(binPath,opts).catch(function(err) {throw err})
/**
* Spawn process with Project Manager,
*
* The standard output and error handles will be inherited, i.e. will be
* redirected to the electron's app output and error handles. Input is piped
* to this process, so it will not be closed, until this process finished.
*
* @param {string[]} args
* @returns Handle to the spawned process.
*/
function spawnProjectManager(args) {
let binPath = projectManagerPath()
let stdin = 'pipe'
let stdout = 'inherit'
let stderr = 'inherit'
let opts = {
stdio: [stdin,stdout,stderr]
}
let out = child_process.spawn(binPath,args,opts)
console.log(`Project Manager has been spawned, pid = ${out.pid}.`)
out.on('exit', (code) => {
console.log(`Project Manager exited with code ${code}.`)
})
return out
}

function runBackend() {
if(args.backend !== false) {
console.log("Starting the backend process.")
withBackend()
return spawnProjectManager()
}
}

async function backendVersion() {
if(args.backend !== false) {
return await withBackend(['--version']).then((t) => t.stdout)
return await execProjectManager(['--version']).then((t) => t.stdout)
}
}

Expand Down

0 comments on commit ba392ea

Please sign in to comment.