ssh tunnel "port already in use"

[expired user #4732]'s profile image [expired user #4732] posted 9 years ago in General Permalink
Hi
I have 3 remote databases and I am using ports 3307, 3308, 3309 to connect to them using ssh tunnel.

Today after an update when HeidiSQL restarted and I tried to connect to first remote database using port 3307 I got error about port already in use. So I closed HeidiSQL in the hope that it will close the plink process as well but HeidiSQL didn't close the running plink process which it uses for ssh tunnel. I had to manually close it from process explorer and I was able to connect to remotedb:3307 successfully. Then I connected to remotedb:3308 and wanted to export a db from remotedb:3308 to remotedb:3307. After selecting the server from dropdown from export dialog I again got port already in use. I then killed the plink process manually again for for 3307 and was able to connect to it.

From my above interaction I noticed 2 things

1. HeidiSQL doesn't close plink session when HeidiSQL is terminated.
2. It doesn't leverage existing connection and try to create new one when database from one server to another server is exported.


Code modification/commit from ansgarbecker, 9 years ago, revision 9.2.0.4964
Try higher ports, up to the 20 next ones, as SSH local port, when the configured one is in use. Fixes connection problems for multiple connected sessions.
Note: PortOpen() needs ~1 second to finish, so we cannot check thousands of other ports.
See http://www.heidisql.com/forum.php?t=18601#p18601
ansgar's profile image ansgar posted 9 years ago Permalink
r4964 should heal that port usage when using more than one connection to the same session, or when exporting to a session which is already open somewhere. HeidiSQL now checks the next higher 20 ports and uses the first one of them which is not in use.

The plink.exe process should be terminated by HeidiSQL - if not, then there is another bug. However, I cannot reproduce that here.

Please login to leave a reply, or register at first.