Skip to content

Handles hooks load error #3244

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ class ParseServer {
Config.validate(AppCache.get(appId));
this.config = AppCache.get(appId);
Config.setupPasswordValidator(this.config.passwordPolicy);
hooksController.load();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should stay here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you validation logic should throw if there's an error loading the hooks, inside the hooks controller.

// Note: Tests will start to fail if any validation happens after this is called.
if (process.env.TESTING) {
Expand Down
79 changes: 45 additions & 34 deletions src/cli/parse-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import definitions from './definitions/parse-server';
import cluster from 'cluster';
import os from 'os';
import runner from './utils/runner';
import AppCache from '../cache';

const help = function(){
console.log(' Get Started guide:');
Expand Down Expand Up @@ -35,49 +36,59 @@ function startServer(options, callback) {

app.use(options.mountPath, api);

const server = app.listen(options.port, options.host, callback);
server.on('connection', initializeConnections);
const hooksController = AppCache.get(options.appId)['hooksController'];
hooksController.load().then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No modifications in that file please. Some people don't use the CLIz

const server = app.listen(options.port, options.host, callback);
server.on('connection', initializeConnections);

if (options.startLiveQueryServer || options.liveQueryServerOptions) {
let liveQueryServer = server;
if (options.liveQueryPort) {
liveQueryServer = express().listen(options.liveQueryPort, () => {
console.log('ParseLiveQuery listening on ' + options.liveQueryPort);
});
if (options.startLiveQueryServer || options.liveQueryServerOptions) {
let liveQueryServer = server;
if (options.liveQueryPort) {
liveQueryServer = express().listen(options.liveQueryPort, () => {
console.log('ParseLiveQuery listening on ' + options.liveQueryPort);
});
}
ParseServer.createLiveQueryServer(liveQueryServer, options.liveQueryServerOptions);
}
ParseServer.createLiveQueryServer(liveQueryServer, options.liveQueryServerOptions);
}

function initializeConnections(socket) {
/* Currently, express doesn't shut down immediately after receiving SIGINT/SIGTERM if it has client connections that haven't timed out. (This is a known issue with node - https://github.com/nodejs/node/issues/2642)
function initializeConnections(socket) {
/* Currently, express doesn't shut down immediately after receiving SIGINT/SIGTERM if it has client connections that haven't timed out. (This is a known issue with node - https://github.com/nodejs/node/issues/2642)

This function, along with `destroyAliveConnections()`, intend to fix this behavior such that parse server will close all open connections and initiate the shutdown process as soon as it receives a SIGINT/SIGTERM signal. */
This function, along with `destroyAliveConnections()`, intend to fix this behavior such that parse server will close all open connections and initiate the shutdown process as soon as it receives a SIGINT/SIGTERM signal. */

const socketId = socket.remoteAddress + ':' + socket.remotePort;
sockets[socketId] = socket;
const socketId = socket.remoteAddress + ':' + socket.remotePort;
sockets[socketId] = socket;

socket.on('close', () => {
delete sockets[socketId];
});
}
socket.on('close', () => {
delete sockets[socketId];
});
}

function destroyAliveConnections() {
for (const socketId in sockets) {
try {
sockets[socketId].destroy();
} catch (e) { /* */ }
function destroyAliveConnections() {
for (const socketId in sockets) {
try {
sockets[socketId].destroy();
} catch (e) { /* */ }
}
}
}

const handleShutdown = function() {
console.log('Termination signal received. Shutting down.');
destroyAliveConnections();
server.close(function () {
process.exit(0);
});
};
process.on('SIGTERM', handleShutdown);
process.on('SIGINT', handleShutdown);
const handleShutdown = function() {
console.log('Termination signal received. Shutting down.');
destroyAliveConnections();
server.close(function () {
process.exit(0);
});
};
process.on('SIGTERM', handleShutdown);
process.on('SIGINT', handleShutdown);
}).catch(() => {
console.error('\u001b[31mERROR: Unable to find _Hooks entries for loading webhooks\u001b[0m');
/*
* Launching Parse Server without loading hooks will cause serious problems.
* So force this process to shutdown before it listens the port.
*/
process.exit(1);
});
}


Expand Down