omrikiei / ktunnel

A cli that exposes your local resources to kubernetes
GNU General Public License v3.0
928 stars 71 forks source link

failed connecting to localhost on port 9002 scheme tcp #22

Closed kukat closed 4 years ago

kukat commented 4 years ago

failed connecting to localhost on port 9002 scheme tcp

ktunnel version 1.2.4 (1.2.5 actually)

my PHPStorm is listening port 9002.

➜  ~ lsof -i :9002
COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
phpstorm 50781 cyao  465u  IPv6 0x32e9aa96a4c0d673      0t0  TCP *:pichat (LISTEN)

And I also tried to start a TCP server to respond to the connection.

➜  ~ nc -vl 9002

same error.

➜  ~ ktunnel -v inject deployment my-php-app 9000:9002 -n playground
INFO[2020-05-01 00:59:00] Injecting tunnel sidecar to playground/my-php-app
INFO[2020-05-01 00:59:01] Waiting for deployment to be ready
INFO[2020-05-01 00:59:23] All pods located for port-forwarding
DEBU[2020-05-01 00:59:23] Injecting to this pods: [my-php-app-6995b778b-8fzm5]
INFO[2020-05-01 00:59:23] Waiting for port forward to finish
INFO[2020-05-01 00:59:24] Forwarding from 127.0.0.1:28688 -> 28688
Forwarding from [::1]:28688 -> 28688
INFO[2020-05-01 00:59:24] starting tcp tunnel from source 9000 to target 9002
DEBU[2020-05-01 00:59:25] attempting to receive from stream
DEBU[2020-05-01 00:59:33] 780fece3-8339-40f4-bcf4-2da5a60fd5de; got session from server: 499<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/www/public/index.php" language="PHP" xdebug:language_version="7.3.17" protocol_version="1.0" appid="38" idekey="PHPSTORM"><engine version="2.7.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright></init>
INFO[2020-05-01 00:59:33] 780fece3-8339-40f4-bcf4-2da5a60fd5de; new session; connecting to port 9002
ERRO[2020-05-01 00:59:33] failed connecting to localhost on port 9002 scheme tcp
omrikiei commented 4 years ago

Hi @kukat, the ktunnel client attempts to dial to localhost:9002, what happens if you try to netcat/telnet/curl manually? are you able to bind? if so, the client has a 50ms dial timeout and maybe increasing it will solve this.

I've released v1.2.6 that includes the actual error in the log message, could you please use that version and let me know what error the client is showing?

kukat commented 4 years ago

Thanks @omrikiei

still failed with the latest v1.2.6, extra error info:

dial tcp [::1]:9002: i/o timeout

❯ ./ktunnel -v inject deployment hip-new-api-part-424 9000:9002 -n playground
INFO[2020-05-04 22:20:53] Injecting tunnel sidecar to playground/hip-new-api-part-424
INFO[2020-05-04 22:20:55] Waiting for deployment to be ready
INFO[2020-05-04 22:21:50] All pods located for port-forwarding
DEBU[2020-05-04 22:21:50] Injecting to this pods: [hip-new-api-part-424-657d599bc6-ttzlt]
INFO[2020-05-04 22:21:50] Waiting for port forward to finish
INFO[2020-05-04 22:21:51] Forwarding from 127.0.0.1:28688 -> 28688
Forwarding from [::1]:28688 -> 28688
INFO[2020-05-04 22:21:51] starting tcp tunnel from source 9000 to target 9002
DEBU[2020-05-04 22:21:52] attempting to receive from stream
DEBU[2020-05-04 22:23:33] e8524eb5-a010-42bd-9759-e78b50c43505; got session from server: 499<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/www/public/index.php" language="PHP" xdebug:language_version="7.3.17" protocol_version="1.0" appid="72" idekey="PHPSTORM"><engine version="2.7.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright></init>
INFO[2020-05-04 22:23:33] e8524eb5-a010-42bd-9759-e78b50c43505; new session; connecting to port 9002
ERRO[2020-05-04 22:23:33] failed connecting to localhost on port 9002 scheme tcp: dial tcp [::1]:9002: i/o timeout
omrikiei commented 4 years ago

I've increased the dial timeout to 500ms in v1.2.7(being released now..). please let me know if it helps

kukat commented 4 years ago

Awesome, 1.2.7 works! Thank you @omrikiei

btw, do you think if it makes sense to add timeout as an argument

kukat commented 4 years ago

also, is there a reconnect strategy? i noticed that if i restart the phpstorm, the connection is dead, i have to quit ktunnel and run ktunnel inject again.

omrikiei commented 4 years ago

Hi @kukat, I'm working on a version that includes the timeout as a cli flag. regarding the reconnect strategy, it shouldn't happen, because on each request a new connection is created to the local machine.. I'll try to reproduce it

omrikiei commented 4 years ago

@kukat I closed and opened phpstorm, and managed to connect with no issue

omrikiei commented 4 years ago

closing issue for now