Archived Forum Post

Index of archived forum posts

Question:

SshTunnel - Connection Issues in New Version

Sep 01 '16 at 14:49

My applications have long been using Chilkat to establish an SSH tunnel and communicate with a MySQL server through that tunnel. It's been working very well, even with multiple connections taking place on the tunnel at the same time.

I recently upgraded from 9.5.0.48 (ChilkatDotNet4.dll) to 9.5.0.58 (ChilkatDotNet46.dll). There were some small modifications I needed to make based on some of the new functionality in the new version, but got everything working properly. I am NOT using dynamic port forwarding.

After the upgrade, I noticed my connections to my MySQL server would fail with a "Reading from the stream has failed" error message. This looks like it occurs when I have two different threads accessing the MySQL server through the tunnel at the same time. It's caused a lot of instability in my applications, and I'm trying to pinpoint it. When I revert back to 9.5.0.48 (ChilkatDotNet4.dll), everything works perfectly fine again. The MySQL and SSH servers have remained constant between my tests, so I've narrowed it to the Chilkat library. Here is how I am establishing my tunnels in both the old and new versions:

Version 9.5.0.48 (ChilkatDotNet4.dll)

    mainTunnel.UnlockComponent("XXXXXX");

    // Set SSH properties
    mainTunnel.SshHostname = sshServer;
    mainTunnel.SshPort = sshPort;
    mainTunnel.SshLogin = sshLogin;
    mainTunnel.SshPassword = sshPassword;

    // Set endpoint properties
    mainTunnel.DestHostname = mysqlServer;
    mainTunnel.DestPort = mysqlPort;

    // Begin accepting connections
    mainTunnel.BeginAccepting(Convert.ToInt32(tunnelPort));

    // Set endpoint properties
    mainTunnel.DestHostname = mysqlServer;
    mainTunnel.DestPort = mysqlPort;

    // Begin accepting connections
    mainTunnel.BeginAccepting(Convert.ToInt32(tunnelPort));

Version 9.5.0.58 (ChilkatDotNet4.dll)

    mainTunnel.UnlockComponent("XXXXXX");
    mainTunnel.DynamicPortForwarding = false;

    // Connect to the SSH server
    if (mainTunnel.Connect(sshServer, sshPort) == false)
    {
        return new KeyValuePair<bool, string>(false, mainTunnel.LastErrorText);
    }

    // Authenticate to the SSH server
    if (mainTunnel.AuthenticatePw(sshLogin, sshPassword) == false)
    {
        return new KeyValuePair<bool, string>(false, mainTunnel.LastErrorText);
    }

    // Set endpoint properties
    mainTunnel.DestHostname = mysqlServer;
    mainTunnel.DestPort = mysqlPort;

    // Begin accepting connections
    if (mainTunnel.BeginAccepting(Convert.ToInt32(tunnelPort)) == false)
    {
        return new KeyValuePair<bool, string>(false, mainTunnel.LastErrorText);
    }