Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-1378

Try every IP address a hostname resolves to when opening the socket

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • 4.0.0
    • Other
    • None

    Description

      When a host name resolves to several addresses (IPv4 and IPv6 on a dual-stack server), the driver only tries the first one: ConnectionHelper.connectSocket builds new InetSocketAddress(host, port), which resolves to a single address.

      If that address is unreachable the connection fails even though the other one would work. With jdbc:mariadb:sequential:// the retry loop hits the same address every time, so with default retriesAllDown and connectTimeout the application waits about before the exception.

      Expected: resolve with InetAddress.getAllByName and try each address in turn, as libmariadb and MySQL Connector/J driver do.

      Why not Happy Eyeballs (RFC 8305): it races a socket per address and closes the losers. That works for HTTP because the server waits for the client to speak first. With the MySQL protocol the server sends its handshake as soon as it accepts, so the losing socket is closed mid-handshake. The server logs an "Aborted connection" and increments the connection error counter for that client IP. The IPv4 and IPv6 client addresses are two distinct entries in the server host cache and only a successful login resets the counter, so the losing family would reach max_connect_errors and get blocked by the server, exactly when it may be needed as a fallback.

      Design:

      • Sequential attempts, moving to the next address on any IOException including timeout, so a silently dropped route falls through.
      • Share the connectTimeout budget between attempts: remaining budget divided by remaining addresses, unused time carries over. The connection phase stays bounded by connectTimeout.
      • Remember the last address that worked per HostAddress and try it first when still resolved, so only the first connection of a pool pays the timeout on a dead address.
      • Keep the JVM address order; java.net.preferIPv6Addresses already controls the family preference.
      • New Socket per attempt, also with a custom socketFactory. Unix sockets and pipes not concerned.

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            diego dupin Diego Dupin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.