Skip to content

Hardcoded 1000ms timeout causes failures in unstable network conditions #42

Open

Description

@lib4x

Description

The current implementation has a hardcoded 1000ms timeout that makes the system fragile in unstable network conditions.

Problem Code

const timeout = setTimeout(async () => {
  await cleanup();
  const val = await ctx.publisher.get(`${ctx.keyPrefix}:sentinel:${streamId}`);
  if (val === DONE_VALUE) {
    resolve(null);
  }
  if (Date.now() - start > 1000) {
    controller.error(new Error("Timeout waiting for ack"));
  }
}, 1000);

Issues

  1. Hardcoded timeout is inflexible: The 1000ms timeout cannot adapt to different network environments
  2. Too aggressive: 1 second may be insufficient for high-latency or unstable networks
  3. Confusing logic: The setTimeout delay and the timeout check both use 1000ms, meaning the timeout error will almost always trigger when the timer fires

Impact

  • Systems fail unnecessarily in slower network conditions
  • No way for users to configure timeout based on their environment
  • Production deployments in high-latency regions become unreliable

Suggested Solutions

Option 1: Configurable Timeout

const timeout = ctx.config.ackTimeout || 5000; // Default to 5s
const timer = setTimeout(async () => {
  await cleanup();
  const val = await ctx.publisher.get(`${ctx.keyPrefix}:sentinel:${streamId}`);
  if (val === DONE_VALUE) {
    resolve(null);
  } else if (Date.now() - start > timeout) {
    controller.error(new Error("Timeout waiting for ack"));
  }
}, timeout);

Option 2: Retry with Backoff

Implement exponential backoff retry logic instead of a single hard timeout.

Environment

  • Network latency: Variable (100ms - 2000ms in our production)
  • This affects production stability

Would you be open to a PR implementing configurable timeouts?

Activity

  1. olefirenko commented on Apr 27, 2026

    @olefirenko

    +1

  2. mdnanocom commented on Jun 25, 2026

    @mdnanocom
    Contributor

    +1

  3. mdnanocom commented on Jun 30, 2026

    @mdnanocom
    Contributor

    in fact i think the root cause to fix is #41
    increasing timeout won't help in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions