Skip to content

RemoteHttpComponent.httpCommand retries a POST on any IOException, so a command the server applied but could not answer is applied twice #8136

Closed

Description

@robfrank

Summary

Noticed while fixing #8062, and deliberately left out of that PR because it is a different invariant: #8062 is about the retry loop re-running a whole transaction BLOCK, this is about the transport re-sending a single COMMAND.

RemoteHttpComponent.httpCommand wraps every send in its own retry loop and retries on IOException. An IOException is raised for a read timeout and for a connection reset as readily as for "the server was never reached", so a POST /api/v1/command whose request the server received and applied, but whose response never made it back, is sent again. The statement runs twice.

Where (HEAD 642f431)

network/src/main/java/com/arcadedb/remote/RemoteHttpComponent.java:406:

      } catch (final IOException | ServerIsNotTheLeaderException e) {
        lastException = e;

        if (!autoReconnect || retry + 1 >= maxRetry)
          break;

        if (connectionStrategy == CONNECTION_STRATEGY.FIXED || stickyPinned) {
          LogManager.instance()
              .log(this, Level.WARNING, "Remote server (%s:%d) seems unreachable, retrying...",
                  connectToServer.getFirst(), connectToServer.getSecond());
        } else {

The FIXED/sticky arm falls through to the next loop iteration and re-sends the identical request to the identical server. (The non-sticky arm is safe inside a transaction: it clears the session and raises TransactionException("Server failover during active transaction").)

The server has the machinery to refuse a replay - IdempotencyCache, keyed on the X-Request-Id request header - but this driver never sends that header:

$ grep -n "X-Request-Id\|HEADER_REQUEST_ID" network/src/main/java/com/arcadedb/remote/*.java
(no output)

and AbstractServerHttpHandler excludes session-bound POSTs from the cache by design anyway (exchange.getRequestHeaders().getFirst(SESSION_ID_HEADER) == null is part of the idempotentPost condition), because a session-scoped request's outcome is not settled until the client commits.

Repro

Point a RemoteDatabase with CONNECTION_STRATEGY.FIXED at a server, run an INSERT, and make the response - not the request - fail (drop the connection after the server has applied the statement, or set a read timeout shorter than the statement takes). The row is inserted twice and the call returns success.

Suggested fix

Two independent halves, either of which narrows it:

  1. Do not retry a send that may have been applied. Java's HttpClient raises HttpConnectTimeoutException for a connection that was never established and a plain HttpTimeoutException/IOException once the request is on the wire; only the former is provably safe to replay for a non-idempotent method. A POST/DELETE that failed after the request was written should propagate rather than loop.
  2. Make it safe to retry when it does: send X-Request-Id and let the server's IdempotencyCache answer the replay. That needs the cache to cover session-bound POSTs, which today it deliberately does not.

Scope / confidence

Code read, with the greps above. The failure needs a response-side network failure, so it is not reproducible by a plain unit test without a proxy or a fault-injecting handler. Falsifiable by showing that the FIXED/sticky arm cannot be reached with a request the server already applied.

Activity

  1. added
    network
    on Sep 22, 2026
  2. added
    severity:major
    on Sep 22, 2026
  3. added this to the 26.10.1 milestone on Sep 22, 2026
  4. self-assigned this
    on Sep 26, 2026
  5. added
    in progress
    on Sep 27, 2026
  6. added a commit that references this issue on Sep 27, 2026
  7. robfrank commented on Sep 30, 2026

    @robfrank
    CollaboratorAuthor

    Fixed in #8527. The remote HTTP client retried a request on any I/O error, including a read timeout or connection reset that happens after the server already received and applied a command, so a lost response could make the same write run twice (on the same server, or on the next one in the cluster). Now a request that may write is retried or failed over only when the error proves it never reached the server (the connection was never established); otherwise the client raises a RemoteException saying the server may already have applied it. Read-only queries and GET requests are still retried as before. With the default settings command() already made a single attempt, so the visible change is for setups with arcadedb.network.sameServerErrorRetry > 0 or HA failover retries.

    Still open:


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  8. removed
    in progress
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugnetworkseverity:major

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions