Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

StartUp Check called twice #18

Open
rommik opened this issue Jul 9, 2019 · 2 comments
Open

StartUp Check called twice #18

rommik opened this issue Jul 9, 2019 · 2 comments

Comments

@rommik
Copy link

rommik commented Jul 9, 2019

I noticed that my StartupCheck is executed twice. I'm not sure if I'm using it wrong or is it by design. Please help me to understand.

I have a simple Express app

const express = require('express');
const path = require('path');
const health = require('@cloudnative/health-connect');

const healthCheck = new health.HealthChecker();
const app = express();

const startPromise = () =>{
  console.log('Start Promise Is called.');
  return new Promise((resolve, reject) => {
    if (true) {
      console.log('Start Up Check Promise called');
      resolve();
    } else {
      reject();
    }
  });
}

const livePromise = () =>
  new Promise((resolve, reject) => {

    if (true) {

      console.log('Liveness probe called');
      resolve();
    } else reject();
  });

const liveCheck = new health.LivenessCheck('liveCheck', livePromise);
healthCheck.registerLivenessCheck(liveCheck);

const ReadinessCheckPromise = () =>
  new Promise((resolve, reject) => {

    if (true) {
      console.log('Readiness Check  called');
      resolve();
    } else reject();
  });
const readinessCheck = new health.ReadinessCheck('ReadinessCheck', ReadinessCheckPromise);
healthCheck.registerReadinessCheck(readinessCheck);

app.use('/status/live', health.LivenessEndpoint(healthCheck));
app.use('/status/ready', health.ReadinessEndpoint(healthCheck));
app.use('/status/healthz', health.HealthEndpoint(healthCheck));

app.listen(3000, () => {

  console.log('running on port 3000');
  const startCheck = new health.StartupCheck('startCheck', startPromise);
  healthCheck.registerStartupCheck(startCheck);
});

In the logs I see

On App Start , the logs look

 MUI running on port 3000
 Start Promise Is called.
 Start Up Check Promise called

On localhost:3000/status/ready:

MUI running on port 3000
Start Promise Is called.
Start Up Check Promise called
++Start Promise Is called.
++Start Up Check Promise called
++Readiness Check  called
++Liveness probe called

++ are marked as Added New Lines
I understand Readiness will perform Liveness check too (once), but why does it perform On StartUp too?

If I do another localhost:3000/status/ready
the logs look

MUI running on port 3000
Start Promise Is called.
Start Up Check Promise called
Start Promise Is called.
Start Up Check Promise called
Readiness Check  called
Liveness probe called
++ Readiness Check  called

Only one line added, as expected.

@rsp
Copy link

rsp commented Oct 18, 2020

@rommik Did you get any reply on that? Is the behavior that you described still an issue?

@rpetersen27
Copy link

Is this going to be addressed at some point? I can confirm that I have the same issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants