Skip to content
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

When a timeout is happens the node process is hanging and not finalized. #156

Open
ddelizia opened this issue Nov 3, 2021 · 0 comments
Open

Comments

@ddelizia
Copy link

ddelizia commented Nov 3, 2021

I have a simple node script that needs to retrieve data for etcd. I have added a policy to deal with timeout (beside a circuit breaker and retry policy).

  • node v14.17.6
  • npm 6.14.15
  • etcd3 1.1.0

The code i am trying to execute is the following:

const timeout = 5000;

const getAllKeys = async () => {

  const timeoutHost = Policy.timeout(timeout, TimeoutStrategy.Aggressive);
  const timeoutHostListener = timeoutHost.onTimeout(() => console.log("timeout while connecting to the host"));
  const circuitBreakerHost = Policy.handleAll().circuitBreaker(5_000, new ConsecutiveBreaker(3));

  const timeoutGlobal = Policy.timeout(timeout, TimeoutStrategy.Cooperative);
  const timeoutGlobalListener = timeoutGlobal.onTimeout(
    () => console.log("timeout on connection to etcd"),
  );
  const retryGlobal = Policy.handleWhen(isRecoverableError).retry().attempts(3);

  const etcd = new Etcd3({
    hosts,
    faultHandling: {
      host: () => Policy.wrap(
        timeoutHost,
        circuitBreakerHost,
      ),
      global: Policy.wrap(
        timeoutGlobal,
        retryGlobal,
      ),
    },
  });

  try {
    const result = await etcd.getAll();
    return result;
  } catch (e) {
    throw e;
  } finally {
    timeoutHostListener.dispose();
    timeoutGlobalListener.dispose();
    etcd.close();
  }
};

getAllKeys().then((watcher) => {
  console.log(`Data: ${JSON.stringify(watcher)}`);
}).catch((err) => {
  console.log("error: " + err);
});

When I have a timeout error, the result is the following:

timeout on connection to etcd
error: Error: Operation timed out after 5000ms

The node process is not able to exit and it is hanging while when there is no timeout the node process finalizes correctly. Not sure if I am missing something or it is a bug.

@ddelizia ddelizia changed the title When a timeout is triggered the process is hanging and not finalized. When a timeout is happens the node process is hanging and not finalized. Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant