ptrd / flupke

Java HTTP3 Client and HTTP3 Server plugin for Kwik
GNU General Public License v3.0
15 stars 4 forks source link

Connect handling (timeout/con refused) is different from JDK HttpClient #10

Closed AlexanderSchuetz97 closed 3 months ago

AlexanderSchuetz97 commented 6 months ago

Hello,

I have noticed that flupkes default connect timeout is 5 seconds. The JDK HttpClient has a default connect timeout of about 40 seconds. (You can test this for example by trying to get "http://1.1.1.1:8888", this server is a DNS server that will not respond with a RST packet and instead just send nothing as a reply to the TCP Syn packets)

Also if the JDK Client connects to a port where no server runs on it gets a ConnectionRefused error and stops immedeately with a ConnectException. Flupke keeps trying until the timeout is reached even if there is no server running. (I am not sure if you can change that due to UDP vs TCP)

Trying to adjust it to be similar to the JDK HttpClient would be appreciated. This is not a high priority as I have just set the timeout in the Builder to 40 seconds now.

ptrd commented 6 months ago

Hi,

1) I have no problem changing the default connect timeout, but I doubt whether the JDK HttpClient has a default of 40 seconds. I've tried with Java 11, 17 and 21 and all seem to use a default of 150 seconds (at least on my machine).

2) That client libs (not only Java) immediately report a "cannot connect" or similar error when the server refuses the connection, is because the server-OS sends a TCP RST packet. There is no equivalent for UDP, because UDP is connection-less ("datagram", "send-and-pray"). So the situation with QUIC/HTTP3 is similar to when a firewall prevents the server from accepting a TCP connection: no packet is returned and one can only conclude the server will not respond by setting a timeout. So your suspicion was right: I cannot change that due to the nature of UDP.

AlexanderSchuetz97 commented 6 months ago

2: is okay. Nothing can be done here.

1: The default timeout should be increased. According to the javadoc (at least if I interprete it correctly) is infinite. But this is as proven by both of us to be not true. I suspect the observed difference of default timeout comes from the OS tcp stack. I think any value between 30s and 3 minutes appears to me like a good default timeout for flupke.

Perhaps add a comment in Http3Builder somewhere that explains the differences.

Ill leave it to you to close this issue when your satisfied with the chanfes you want to do (if any)

Thank you

ptrd commented 6 months ago

Yes, that sounds very likely, didn't think of that. And I agree with the proposed change. Will fix it somewhere in the coming days.

Thanks for your input!

ptrd commented 3 months ago

https://github.com/ptrd/flupke/commit/fe73aca571603fe541a623c7cb4d22a6f5ba0f12