Skip to content

Unable to Connect to Firebird using Jaybird JDBC with SOCKS5 Proxy: Exception in thread "main" java.sql.SQLNonTransientConnectionException: Unable to complete network request to host "localhost". [SQLState:08006, ISC error code:335544721] #826

@qijinkui

Description

@qijinkui

I am encountering an issue when trying to connect to a Firebird database using the Jaybird JDBC driver with a SOCKS5 proxy. The connection works fine when connecting directly to the database without using the proxy, but when I try to use the SOCKS5 proxy, I receive the following error:

Exception in thread "main" java.sql.SQLNonTransientConnectionException: Unable to complete network request to host "localhost". [SQLState:08006, ISC error code:335544721]
	at org.firebirdsql.gds.ng.FbExceptionBuilder$Type$5.createSQLException(FbExceptionBuilder.java:677)
	at org.firebirdsql.gds.ng.FbExceptionBuilder$ExceptionInformation.toSQLException(FbExceptionBuilder.java:571)
	at org.firebirdsql.gds.ng.FbExceptionBuilder.toSQLException(FbExceptionBuilder.java:309)
	at org.firebirdsql.gds.ng.wire.WireConnection.socketConnect(WireConnection.java:298)

Caused by: java.net.SocketException: SOCKS: Connection refused
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:564)
	at java.net.Socket.connect(Socket.java:606)
	at org.firebirdsql.gds.ng.wire.WireConnection.socketConnect(WireConnection.java:288)

Steps to Reproduce:

  • Jaybird Version: I am using Jaybird 5.0.6 for Java 8.
  • Firebird Version: I am connecting to Firebird 2.5.6.
  • SOCKS5 Proxy: I am running a local SOCKS5 proxy via Docker from the following image:
    Proxy Image: xkuma/socks5
  • Custom Code in Jaybird: I have extended the WireConnection.java class to support SOCKS5 proxy connections. Specifically, I modified the socketConnect method to use a proxy if specified. Below is the relevant code I added to create a socket with the SOCKS5 proxy:
    protected Socket createSocket() {
        // Check if a proxy server is specified
        String proxyServerName = dbAttachInfo.getProxyServerName();
        if (proxyServerName == null || proxyServerName.isEmpty()) {
            return new Socket();  // No proxy, create a regular socket
        }
    
        // Use SOCKS proxy
        int proxyPortNumber = dbAttachInfo.getProxyPortNumber();
        return new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxyServerName, proxyPortNumber)));
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions