Skip to content

[BUG] HTTP sync long polling repeats successful polls ten times per loop #6523

Description

@Aias00

Search before asking

  • I had searched in the issues and found no similar issues.

Apache ShenYu Component

shenyu-sync-data-http

What happened

HttpSyncDataService.HttpLongPollingTask.run() retries failed long-poll requests with a for (time = 1; time <= retryTimes; time++) loop, but it does not leave that retry loop after a successful doLongPolling(server) call.

Current code in shenyu-sync-data-center/shenyu-sync-data-http/src/main/java/org/apache/shenyu/sync/data/http/HttpSyncDataService.java:

while (RUNNING.get()) {
    int retryTimes = 10;
    for (int time = 1; time <= retryTimes; time++) {
        try {
            //do long polling.
            doLongPolling(server);
        } catch (Exception e) {
            if (time < retryTimes) {
                ThreadUtils.sleep(TimeUnit.SECONDS, 5);
                continue;
            }
            ThreadUtils.sleep(TimeUnit.MINUTES, 5);
        }
    }
}

When doLongPolling(server) succeeds, execution continues to the next for iteration. A single outer loop can therefore perform 10 successful long-poll requests back-to-back instead of one successful poll followed by the next outer loop cycle.

This can create unnecessary long-poll traffic and makes the retry counter behave as a fixed repeat count even when no retry is needed.

What you expected to happen

After a successful doLongPolling(server) call, the retry loop should stop for the current outer iteration, for example by break-ing out of the for loop. The retry loop should only continue after failures.

How to reproduce

  1. Configure ShenYu bootstrap to use HTTP sync.
  2. Start admin and bootstrap while the long-poll endpoint is healthy.
  3. Observe that HttpLongPollingTask.run() can execute doLongPolling(server) up to 10 times per outer while (RUNNING.get()) loop because success does not break the retry loop.

Debug logs

No response

Environment

Current master branch.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

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