Skip to content

Latest commit

 

History

History
34 lines (28 loc) · 1.11 KB

rolling_update.md

File metadata and controls

34 lines (28 loc) · 1.11 KB

問題

當使用Rolling Update時,預期更新期間不影響使用者體驗。
但實際有機率出現 "Server is busy" 錯誤。

原因

if (options.serverReady === false) 
  next(new Error('Server is busy'));

當新程式啟動時,未等待serverReady,即被加入Load Balancer處理新進入的request。

解決方法

尋找方法,使新程式啟動時可以等待 serverReady 後,才加入Load Balancer處理。

Elastic Beanstalk Deployment

Deployment Documentation

If a health check URL is configured, the load balancer doesn't route traffic to the updated instances until they return a 200 OK status code in response to an HTTP GET request to the health check URL.

程式修改

const { Timer } = require('nodejs-timer');

const readyCheckTimer = new Timer(() => {
  if (!options.serverReady) {
    readyCheckTimer.start(1000);
    return;
  }
  server.listen(process.env.PORT);
});

readyCheckTimer.start(1000);

每秒巡一次是否 serverReady,直到serverReady才listen。