From fcb7ae5adedfbd454b7c0cb180e40b8b6c78c4c3 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 25 Dec 2024 16:12:04 +0900 Subject: [PATCH] ensured call the cancellation function for ssh connection --- server-peer.go | 2 +- server-proxy.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/server-peer.go b/server-peer.go index 5ef37b4..4939be6 100644 --- a/server-peer.go +++ b/server-peer.go @@ -68,7 +68,7 @@ func (spc *ServerPeerConn) RunTask(wg *sync.WaitGroup) { // set up a timer to set waiting duration until the connection is // actually established on the client side and it's informed... - waitctx, cancel_wait = context.WithTimeout(spc.route.cts.svr.ctx, 4 * time.Second) + waitctx, cancel_wait = context.WithTimeout(spc.route.cts.svr.ctx, 5 * time.Second) // TODO: make this configurable wait_for_started: for { select { diff --git a/server-proxy.go b/server-proxy.go index 92e9588..7a9e9bc 100644 --- a/server-proxy.go +++ b/server-proxy.go @@ -454,7 +454,7 @@ func (pxy *server_proxy_http_main) ServeHTTP(w http.ResponseWriter, req *http.Re client = &http.Client{ Transport: transport, CheckRedirect: prevent_follow_redirect, - Timeout: 4 * time.Second, // TODO: make this configurable.... + Timeout: 5 * time.Second, // TODO: make this configurable.... } resp, err = client.Do(proxy_req) //resp, err = transport.RoundTrip(proxy_req) @@ -617,14 +617,15 @@ func (pxy *server_proxy_ssh_ws) connect_ssh (ctx context.Context, username strin User: username, Auth: []ssh.AuthMethod{ ssh.Password(password) }, HostKeyCallback: ssh.InsecureIgnoreHostKey(), - // Timeout: 2 * time.Second , + // Timeout: 5 * time.Second , // timeout is also set on the passed ctx. it may not been needed here. } -// CHECK OPTIONS - // if r.svc_option & RouteOption(ROUTE_OPTION_SSH) == 0 { - // REJECT?? - //} -// TODO: timeout... +/* Is this protection needed? + if r.svc_option & RouteOption(ROUTE_OPTION_SSH) == 0 { + err = fmt.Errorf("peer not ssh") + goto oops + } +*/ addr = svc_addr_to_dst_addr(r.svc_addr); @@ -767,6 +768,7 @@ ws_recv_loop: conn_ready_chan <- true } } + connect_ssh_cancel() connect_ssh_cancel = nil }() }