0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🐛 Fixed urls being /404/ after starting the Ghost server

no issue

- there was a timing bug in Ghost
- we do operations in parallel on bootstrap
  - 1) we fetch the resources as early as possible
  - 2) we do all the rest (express bootstrapping, theme loading, router registration) etc.
- it can happen that (2) happens too slow and ends in the situation that the queue, which is responsible
  to handle both parallel actions, does not wait for the routers and closes the event
- this is a short term fix
- i need to reconsider if there is a better long term fix
This commit is contained in:
kirrg001 2018-06-07 09:14:58 +02:00
parent 2f69e51018
commit 3155ea2aa7
3 changed files with 37 additions and 2 deletions

View file

@ -82,6 +82,7 @@ class Queue extends EventEmitter {
if (!this.queue.hasOwnProperty(options.event)) {
this.queue[options.event] = {
tolerance: options.tolerance,
requiredSubscriberCount: options.requiredSubscriberCount || 0,
subscribers: []
};
}
@ -136,7 +137,8 @@ class Queue extends EventEmitter {
delete this.toNotify[action];
debug('ended (1)', event, action);
this.emit('ended', event);
} else if (this.toNotify[action].timeoutInMS > this.queue[event].tolerance) {
} else if (this.queue[options.event].subscribers.length >= this.queue[options.event].requiredSubscriberCount &&
this.toNotify[action].timeoutInMS > this.queue[event].tolerance) {
delete this.toNotify[action];
debug('ended (2)', event, action);
this.emit('ended', event);
@ -159,6 +161,7 @@ class Queue extends EventEmitter {
if (!this.queue.hasOwnProperty(options.event)) {
this.queue[options.event] = {
tolerance: options.tolerance || 0,
requiredSubscriberCount: options.requiredSubscriberCount || 0,
subscribers: []
};
}

View file

@ -126,7 +126,8 @@ class Resources {
// CASE: all resources are fetched, start the queue
this.queue.start({
event: 'init',
tolerance: 100
tolerance: 100,
requiredSubscriberCount: 1
});
});
}

View file

@ -241,5 +241,36 @@ describe('Unit: services/url/Queue', function () {
timeoutInMS: 20
});
});
it('late subscribers', function (done) {
let notified = 0;
let called = 0;
queue.addListener('ended', function (event) {
event.should.eql('nachos');
notified.should.eql(1);
called.should.eql(1);
done();
});
setTimeout(function () {
queue.register({
event: 'nachos',
tolerance: 100,
timeoutInMS: 20,
requiredSubscriberCount: 1
}, function () {
called = called + 1;
notified = notified + 1;
});
}, 500);
queue.start({
event: 'nachos',
tolerance: 60,
timeoutInMS: 20,
requiredSubscriberCount: 1
});
});
});
});