microsoft / microsoft/etcd3

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

Open
#156 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
546
Forks
76
Avg merge
22h 46m
Merged PRs (30d)
13

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the timeout using the shown getAllKeys script and inspect the lifecycle around the timeout policies and etcd.close() in the finally block. Trace which resources remain open after the timeout, then verify that the process exits after cleanup while preserving the reported timeout behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.