Verified Commit 8a2c4d1d authored by Aral Balkan's avatar Aral Balkan
Browse files

Fixes #231: Redundant server close call causing restart failure

  - Also, downgrade version to 14.6.3 to release as a backward-compatible fix in the 14.x line.
parent aa12a997
......@@ -10,9 +10,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [TODO] (Breaking change.) DotJS routes can now specify any number of parameters and static route fragments. This is potentially a breaking change for existing sites if they used underscores in the names of dynamic routes as these have now gained special significance and will be interpreted as parameter (single) and path (double) delimiters. (#230)
## [14.6.3] - 2020-08-31
### Fixed
- [TODO] Restart requests that are fired while a restart is already in progress no longer fail. (Regular processes, as daemon processes use a different – simpler – technique and are not affected by this bug.) (#231)
- Redundant server close call causing subsequent restart attempts to fail (#231)
## [14.6.2] - 2020-08-30
......
......@@ -906,10 +906,7 @@ class Site {
// Close all active connections on the server.
// (This is so that long-running connections – e.g., WebSockets – do not block the exit.)
this.server.destroy()
// Stop accepting new connections.
this.server.close( () => {
this.server.destroy(() => {
// OK, it’s time to go :)
this.log('\n 💕 ❨site.js❩ Goodbye!\n')
done()
......@@ -1090,13 +1087,19 @@ class Site {
// Restarts the server.
restartServer () {
async restartServer () {
if (process.env.NODE_ENV === 'production') {
// We’re running production, to restart the daemon, just exit.
// (We let ourselves fall, knowing that systemd will catch us.) ;)
process.exit()
} else {
// We’re running as a regular process. Just restart the server, not the whole process.
if (this.restartingRegularProcess) {
this.log(' 🙈 ❨site.js❩ Server restart requested while one is already in process. Ignoring…')
return
}
this.restartingRegularProcess = true
// Do some housekeeping.
Graceful.off('SIGINT', this.goodbye)
......@@ -1109,24 +1112,20 @@ class Site {
// Wait until housekeeping is done cleaning up after the server is destroyed before
// restarting the server.
this.eventEmitter.on('housekeepingIsDone', () => {
this.eventEmitter.on('housekeepingIsDone', async () => {
// Restart the server.
this.eventEmitter.removeAllListeners()
this.log('\n 🐁 ❨site.js❩ Restarting server…\n')
const {commandPath, args} = cli.initialise(process.argv.slice(2))
this.serve(args)
this.log(' 🐁 ❨site.js❩ Server restarted.\n')
await this.serve(args)
this.log('\n 🐁 ❨site.js❩ Server restarted.\n')
this.restartingRegularProcess = false
})
// Destroy the current server (so we do not get a port conflict on restart before
// we’ve had a chance to terminate our own process).
this.server.destroy()
// Stop accepting new connections.
this.server.close(() => {
this.log('\n 🐁 ❨site.js❩ Server is closed.\n')
this.server.removeAllListeners('close')
this.server.removeAllListeners('error')
this.server.destroy(() => {
this.log('\n 🐁 ❨site.js❩ Server destroyed.\n')
})
}
}
......@@ -1173,21 +1172,21 @@ class Site {
ignoreInitial: true
})
this.app.__fileWatcher.on ('all', (event, file) => {
this.app.__fileWatcher.on ('all', async (event, file) => {
if (file.includes('/.dynamic')) {
//
// Dynamic route change.
//
this.log(` 🐁 ❨site.js❩ Dynamic route change: ${clr(`${this.prettyFileWatcherEvent(event)}`, 'green')} (${clr(file, 'cyan')}).`)
this.log('\n 🐁 ❨site.js❩ Requesting restart…\n')
this.restartServer()
await this.restartServer()
} else if (file.includes('/.wildcard')) {
//
// Wildcard route change.
//
this.log(` 🐁 ❨site.js❩ Wildcard route change: ${clr(`${this.prettyFileWatcherEvent(event)}`, 'green')} (${clr(file, 'cyan')}).`)
this.log('\n 🐁 ❨site.js❩ Requesting restart…\n')
this.restartServer()
await this.restartServer()
}
})
......
{
"name": "@small-tech/site.js",
"version": "15.0.0",
"version": "14.6.3",
"description": "Small Web construction set.",
"keywords": [
"web server",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment