binarywang/WxJava · error · WxRuntimeException

微信服务端异常,超出重试次数

Error message

微信服务端异常,超出重试次数

What it means

Thrown as WxRuntimeException when the CP Third-Party Platform (TP) service exhausts all retry attempts in the execute() method. The retry loop only retries on WeChat error code -1 (system busy) with exponential backoff (retrySleepMillis * 2^retryTimes). When retryTimes + 1 exceeds maxRetryTimes, the original WxErrorException is discarded and replaced with this generic runtime exception.

Source

Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java:399

   * @param <T>                     the type parameter
   * @param <E>                     the type parameter
   * @param executor                the executor
   * @param uri                     the uri
   * @param data                    the data
   * @param withoutSuiteAccessToken the without suite access token
   * @return the t
   * @throws WxErrorException the wx error exception
   */
  public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data, boolean withoutSuiteAccessToken) throws WxErrorException {
    int retryTimes = 0;
    do {
      try {
        return this.executeInternal(executor, uri, data, withoutSuiteAccessToken);
      } catch (WxErrorException e) {
        if (retryTimes + 1 > this.maxRetryTimes) {
          log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
          //最后一次重试失败后,直接抛出异常,不再等待
          throw new WxRuntimeException("微信服务端异常,超出重试次数");
        }

        WxError error = e.getError();
        /*
         * -1 系统繁忙, 1000ms后重试
         */
        if (error.getErrorCode() == -1) {
          int sleepMillis = this.retrySleepMillis * (1 << retryTimes);
          try {
            log.debug("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
            Thread.sleep(sleepMillis);
          } catch (InterruptedException e1) {
            Thread.currentThread().interrupt();
          }
        } else {
          throw e;
        }
      }

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Check WeChat platform status for ongoing outages or maintenance windows
  2. Increase retry budget: service.setMaxRetryTimes(10) and service.setRetrySleepMillis(2000)
  3. Verify network stability and proxy configuration between your server and qyapi.weixin.qq.com
  4. Implement a circuit breaker (e.g., Resilience4j) to fail-fast during sustained outages instead of burning all retries

Example fix

// before
service.setMaxRetryTimes(5);
service.setRetrySleepMillis(1000);

// after
service.setMaxRetryTimes(10);
service.setRetrySleepMillis(2000);
Defensive patterns

Strategy: try-catch

Try / catch

try {
  service.execute(executor, uri, data);
} catch (WxRuntimeException e) {
  if (e.getMessage().contains("超出重试次数")) {
    // All retries exhausted on errcode -1
    log.error("WeChat CP API unavailable after retries", e);
    // fall back to cached data, queue for later, or alert
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: WeChat CP TP API endpoint repeatedly returns errcode -1 (system busy) across every retry attempt. The throw fires inside the catch block at line 399 when retryTimes + 1 > maxRetryTimes evaluates true.

Common situations: WeChat backend sustained outage or maintenance window; unstable network proxy causing repeated timeouts; maxRetryTimes set too low (default 5); high-frequency API calls during WeChat peak traffic.

Related errors


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/b06ede76d98341d2. Report an issue: GitHub.