-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
yuki-takeichi
wants to merge
1
commit into
parse-community:master
from
yuki-takeichi:handle-hooks-load-error
Closed
Handles hooks load error #3244
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:'); | ||
|
@@ -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(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
}); | ||
} | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should stay 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.
And you validation logic should throw if there's an error loading the hooks, inside the hooks controller.