Skip to content

Commit ef92153

Browse files
committed
fix: avoid bind exception when reconnecting after failure
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 98be0a6 commit ef92153

File tree

1 file changed

+5
-1
lines changed
  • src/main/kotlin/com/redhat/devtools/gateway/openshift

1 file changed

+5
-1
lines changed

src/main/kotlin/com/redhat/devtools/gateway/openshift/Pods.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import java.io.IOException
3838
import java.io.InputStream
3939
import java.io.OutputStream
4040
import java.net.InetAddress
41+
import java.net.InetSocketAddress
4142
import java.net.ServerSocket
4243
import java.net.Socket
4344
import java.util.concurrent.TimeUnit
@@ -99,7 +100,10 @@ class Pods(private val client: ApiClient) {
99100
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-latest/src/main/java/io/kubernetes/client/examples/PortForwardExample.java
100101
@Throws(IOException::class)
101102
fun forward(pod: V1Pod, localPort: Int, remotePort: Int): Closeable {
102-
val serverSocket = ServerSocket(localPort, 50, InetAddress.getLoopbackAddress())
103+
val serverSocket = ServerSocket()
104+
serverSocket.use {
105+
it.bind(InetSocketAddress(InetAddress.getLoopbackAddress(), localPort))
106+
}
103107

104108
val scope = CoroutineScope(Dispatchers.IO)
105109
scope.launch {

0 commit comments

Comments
 (0)