apache/shenyu · error · IllegalArgumentException

Unsupported SocketAddress type

Error message

Unsupported SocketAddress type: ${socketAddress.getClass().getName()}

What it means

TcpBootstrapServer.getIp only supports java.net.InetSocketAddress for extracting the peer host; any other SocketAddress implementation is logged and rejected with IllegalArgumentException('Unsupported SocketAddress type: <class>'). The gateway's TCP protocol handling expects an IP-socket peer and cannot derive an address from other address families (e.g. Unix domain sockets, custom address types).

Solutions

  1. Connect clients to the TCP gateway over TCP/IP so remote addresses are InetSocketAddress instances.
  2. If Unix domain sockets are required, extend getIp (or the surrounding handler) to handle DomainSocketAddress explicitly and extract the path instead of the host.
  3. Audit any custom Netty channel/transport configuration that could supply non-inet remote addresses.
  4. In tests, provide real InetSocketAddress mocks rather than generic SocketAddress fakes.

Example fix

// before
if (socketAddress instanceof InetSocketAddress) { ... }
// after
if (socketAddress instanceof InetSocketAddress isa) { return isa.getHostString(); }
if (socketAddress instanceof DomainSocketAddress dom) { return dom.path(); }
Defensive patterns

Strategy: type-guard

Validate before calling

SocketAddress addr = connection.remoteAddress();
if (!(addr instanceof InetSocketAddress)) { /* reject non-IP transports */ }

Type guard

static boolean isIpSocket(SocketAddress addr) {
    return addr instanceof InetSocketAddress;
}
// usage
if (!isIpSocket(socketAddress)) { /* unsupported transport: reject */ }

Try / catch

try {
    String ip = getIp(socketAddress);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Unsupported SocketAddress type")) { /* handle non-inet transport or reject */ }
    throw e;
}

Prevention

When it happens

Trigger: getIp (invoked from the TCP client handler) receives a remoteAddress that is not an InetSocketAddress — e.g. DomainSocketAddress from Unix-domain sockets or a third-party/custom SocketAddress subclass attached to the connection.

Common situations: Running the TCP gateway over Unix domain sockets or exotic transports; frameworks or tests injecting mock SocketAddress implementations; custom Netty channel configurations that report non-inet addresses.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/8f4feb7f22f8ebb1. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-protocol/shenyu-protocol-tcp/src/main/java/org/apache/shenyu/protocol/tcp/TcpBootstrapServer.java:121

        client.subscribe(
            clientConn -> bridge.bridge(serverConn, clientConn),
            error -> {
                LOG.error("Failed to establish client connection for {}", serverConn, error);
                eventBus.unregister(connectionObserver);
                serverConn.dispose();
            }
        );
    }

    private String getIp(final SocketAddress socketAddress) {
        if (Objects.isNull(socketAddress)) {
            throw new NullPointerException("remoteAddress is null");
        }
        if (socketAddress instanceof InetSocketAddress) {
            return ((InetSocketAddress) socketAddress).getHostString();
        }
        LOG.error("Unsupported SocketAddress type: {}", socketAddress.getClass().getName());
        throw new IllegalArgumentException("Unsupported SocketAddress type: " + socketAddress.getClass().getName());
    }

    /**
     * doOnUpdate.
     *
     * @param removeList removeList
     */
    @Override
    public void removeCommonUpstream(final List<DiscoveryUpstreamData> removeList) {
        eventBus.post(removeList);
    }


    /**
     * shutdown.
     */
    @Override
    public synchronized void shutdown() {

View on GitHub (pinned to 567142e072)