Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
fix(backend): collection of minor fixes (#174)
Browse files Browse the repository at this point in the history
- respect do not blackbox internal setting,
- use SIGINT to kill process instead of SIGKILL,
- pass path to chokidar's watcher.add method argument,
- close frontend if backend is dead when debugFrontend.
  • Loading branch information
alexkozy committed Nov 19, 2018
1 parent 2a588a8 commit e0595e3
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 7 deletions.
3 changes: 3 additions & 0 deletions debug.js
@@ -0,0 +1,3 @@
#!/usr/bin/env node
process.env.NDB_DEBUG_FRONTEND = 1;
require('./ndb.js');
19 changes: 18 additions & 1 deletion front_end/ndb/NdbMain.js
Expand Up @@ -71,7 +71,8 @@ Ndb.NdbMain = class extends Common.Object {
const blackboxInternalScripts = Common.moduleSetting('blackboxInternalScripts').get();
const regexPatterns = Common.moduleSetting('skipStackFramesPattern').getAsArray()
.filter(({pattern}) => pattern !== '^internal[\\/].*');
regexPatterns.push({pattern: '^internal/.*' });
if (blackboxInternalScripts)
regexPatterns.push({pattern: '^internal/.*' });
Common.moduleSetting('skipStackFramesPattern').setAsArray(regexPatterns);
}
};
Expand Down Expand Up @@ -398,3 +399,19 @@ SDK.TextSourceMap.load = async function(sourceMapURL, compiledURL) {
return null;
}
};

(async function() {
if (!Runtime.queryParam('debugFrontend'))
return;
const [info, backend] = await Promise.all([getProcessInfo(), Runtime.backendPromise]);
const service = await backend.createService(info.serviceDir + '/ping.js');
checkBackend();

async function checkBackend() {
const timeout = setTimeout(() => window.close(), 3000);
service.ping().then(() => {
clearTimeout(timeout);
setTimeout(checkBackend, 3000);
});
}
})();
3 changes: 1 addition & 2 deletions lib/launcher.js
Expand Up @@ -25,9 +25,8 @@ const fsWriteFile = util.promisify(fs.writeFile);

process.on('unhandledRejection', error => {
// Will print "unhandledRejection err is not defined"
if (error.message.includes('Protocol error') && error.message.includes('Target closed')) {
if (error.message.includes('Protocol error') && error.message.includes('Target closed'))
process.exit(1);
}
console.log('unhandledRejection', error.message);
});

Expand Down
1 change: 1 addition & 0 deletions lib/preload.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/process_utility.js
Expand Up @@ -7,7 +7,7 @@
module.exports = prepareProcess;

function prepareProcess(disposeCallback) {
process.on('uncaughtException', (error) => {
process.on('uncaughtException', error => {
// mute carlo rpc errors
if (error.message === 'Channel closed')
return;
Expand Down
12 changes: 10 additions & 2 deletions services/file_system.js
Expand Up @@ -7,7 +7,15 @@
const { rpc, rpc_process } = require('carlo/rpc');
const chokidar = require('chokidar');
const fs = require('fs');
const { URL } = require('url');
const { URL, fileURLToPath } = require('url');

function urlToPlatformPath(fileURL) {
if (fileURLToPath)
return fileURLToPath(fileURL);
if (process.platform === 'win32')
return fileURL.substr('file:///'.length).replace(/\//g, '\\');
return fileURL.substr('file://'.length);
}

class FileSystemHandler {
constructor() {
Expand Down Expand Up @@ -39,7 +47,7 @@ class FileSystemHandler {
try {
const names = fs.readdirSync(url);
const urlString = url.toString();
if (this._watcher) this._watcher.add(urlString);
if (this._watcher) this._watcher.add(urlToPlatformPath(urlString));
names.forEach(name => {
if (name === '.git') gitFolders.add(urlString.substr(fileURL.length + 1));
const fileName = urlString + '/' + name;
Expand Down
2 changes: 1 addition & 1 deletion services/ndd_service.js
Expand Up @@ -189,7 +189,7 @@ class NddService {
kill(id) {
if (!this._running.has(id))
return;
process.kill(id, 'SIGKILL');
process.kill(id, 'SIGINT');
for (const nddStore of this._nddStores)
fs.unlink(path.join(nddStore, id), _ => 0);
}
Expand Down
21 changes: 21 additions & 0 deletions services/ping.js
@@ -0,0 +1,21 @@
/**
* @license Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

const { rpc, rpc_process } = require('carlo/rpc');

class Handler {
constructor() {
require('../lib/process_utility.js')(() => this.dispose());
}

ping() {}

dispose() {
Promise.resolve().then(() => process.exit(0));
}
}

rpc_process.init(() => rpc.handle(new Handler()));

0 comments on commit e0595e3

Please sign in to comment.