apache/shardingsphere · error · UnsupportedOperationException

Can not support type `%s`.

Error message

Can not support type `%s`.

What it means

MySQL error 1043 (ER_BAD_HANDSHAKE) thrown by the proxy's MySQL authentication engine when the handshake response packet (MySQLHandshakeResponse41Packet) cannot be parsed — specifically when parsing runs past the end of the payload (IndexOutOfBoundsException). It means the client sent a malformed or truncated handshake response, so the proxy cannot recover username, auth response, or database and closes the negotiation with HandshakeException.

Source

Thrown at agent/plugins/metrics/type/prometheus/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/PrometheusMetricsCollectorFactory.java:48

 * Metrics collector factory of Prometheus.
 */
public final class PrometheusMetricsCollectorFactory implements MetricsCollectorFactory {
    
    @Override
    public MetricsCollector create(final MetricConfiguration metricConfig) {
        switch (metricConfig.getType()) {
            case COUNTER:
                return new PrometheusMetricsCounterCollector(metricConfig);
            case GAUGE:
                return new PrometheusMetricsGaugeCollector(metricConfig);
            case HISTOGRAM:
                return new PrometheusMetricsHistogramCollector(metricConfig);
            case SUMMARY:
                return new PrometheusMetricsSummaryCollector(metricConfig);
            case GAUGE_METRIC_FAMILY:
                return new PrometheusMetricsGaugeMetricFamilyCollector(metricConfig);
            default:
                throw new UnsupportedOperationException(String.format("Can not support type `%s`.", metricConfig.getType()));
        }
    }
    
    @Override
    public String getType() {
        return "Prometheus";
    }
}

View on GitHub (pinned to e952770a21)

Solutions

  1. Verify the client actually speaks MySQL protocol and connects to the MySQL frontend port of the proxy, not another dialect's port.
  2. Upgrade the MySQL client/driver to a version that sends a standard Handshake Response 41 packet.
  3. Check the proxy WARN log — it prints a hex dump of the received handshake — and compare it against the expected Handshake Response 41 layout to find the truncation point.
  4. If using TLS, align client ssl-mode with whether the proxy expects an SSL request packet first; remove intermediate proxies that mangle the byte stream.

Example fix

// before
mysql -h proxy-host -P 3307 ... # but 3307 is the postgresql frontend port

// after
mysql -h proxy-host -P 3306 ... # connect to the MySQL frontend port
Defensive patterns

Strategy: validation

Validate before calling

// Verify the endpoint speaks MySQL before connecting
try (Socket s = new Socket(host, port)) {
    byte[] greeting = s.getInputStream().readNBytes(5);
    if (greeting.length < 4 || (greeting[3] & 0xff) == 0) {
        throw new IOException("Not a MySQL protocol endpoint");
    }
}

Try / catch

// Driver surfaces SQLNonTransientConnectionException wrapping error 1043;
// do not retry — fix the client/endpoint instead:
try {
    conn = DriverManager.getConnection(url, user, pass);
} catch (SQLNonTransientConnectionException e) {
    // check proxy WARN log hex dump; verify client version, TLS mode, and port
    throw new IllegalStateException("Bad handshake: wrong port/protocol or outdated client", e);
}

Prevention

When it happens

Trigger: Connecting with a client that sends a handshake response shorter or differently laid out than Handshake Response 41 expects: truncated TCP payload, non-MySQL protocol bytes sent to port 3307, a very old client (pre-4.1 protocol) that sends Handshake Response 320, or a TLS-capable client that missequences its SSL negotiation.

Common situations: Pointing a PostgreSQL/other protocol client or a health-check TCP probe at the MySQL proxy port; old MySQL client libraries; middleware/LB (e.g. HAProxy in tcp mode with a bogus probe) writing bytes into the stream; clients with a bad ssl-mode setting; version mismatch between client protocol and proxy expectations.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/a5d514a12c368cd7. Report an issue: GitHub.