-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TLSHandshake Verification only on first request #2
Comments
I haven't seen this anywhere else. The code is also fairly simple around checking for SSL certs so I would imagine it's working as expected as well. When you say "every request after" do you mean when there is a redirect? Also, what's the value of |
I believe I found the issue. When the web server starts and makes the first request, it takes a bit extra time for the tls_handshake because it needs to parse the certpool. For example. I pass it a url "google.com", and the tls_handshake will be 350ms for example on the very first request of the web server. I request again and its 50ms. Also, it doesn't matter if I request google.com on the first request, and a completely different domain every request after, only the very first has that extra time. Do you see this when you run it? I have a solution implemented on my end that I can create a PR for if you do. |
Thank you. I can't see the same on the TLS but DNS gets faster which is expected (see below).
|
Run the same test using https on the domains. This issue is only for SSL for the initial parsing of the certs. If you start the web server, and hit https://google.com, then hit it again, you will see a difference. Let me know if you see what I mean. |
Here are the responses for
This both cases, TLS Handshake is longer on the first request and so is the DNS lookup time. I guess I'm not understanding the underlying issue. As far as I understood, you think only the first request is verified for correct TLS certs, because it takes longer. However they are all checked for handshake but it takes less time after they cert is parsed on the server. What am I missing here in terms of the original issue? |
So dns_lookup isn't a problem. The first time it's a little more, but it jumps around, and is similar the 5th call. Now, the "tls_handshake" goes from ~163ms the first time, down to about 25ms every time after. I could be wrong, but I believe this extra time is the server parsing the certpool on the first request. If we have a web service for returning the total time through the lifecycle, I would expect we would want the times from the 2nd+ calls, and not account for the web server parsing the certs the first time. An example:
Adding this to the top of the main func will prep the root certs on web server start, and not on the first request. After adding this, you will see every request, including the first is much closer on time, instead of being so much longer the first request. -- Quick Note Please let me know if I misunderstand the process a bit. I'm new to golang and am just experimenting. |
Also, a tool like httpstat will return this extra latency on every request, but when used through the web server, only the first request has the extra. I would assume we don't want to account for that extra time? |
I understand your point now. I think this behavior depends on what the service is used for. If it is going to be used as a service to provide consistent reading of a website latency and its chain, then I'd agree reseting the cache or warming them up (if possible) is a good option. However if it is to be used to check website availability and the metrics provided are there to identify where the issues are (like a tracer) then adding cache reset is not the best option as it severely impacts its performance in multi-tenanted environments. One can imagine cache reset being optional as a param during startup to cater for both cases. |
Sorry if I misunderstand, and thanks for reviewing this with me. I don't see how the extra latency on the first request can be linked to the actual site at all? For example. Web server starts, I request https://google.com to get the numbers. I get total numbers that are about 200 - 300 ms larger since its the first request. Then I check https://microsoft.com. Site is up but the total time I get is 200-300 ms LESS than what I would get, if Microsoft was the first site I checked when the web service started. Likewise, if first request is Microsoft, second is google, then Microsoft is 200 - 300ms longer than it would be if it were the 2+ request after web server starts. Based on this, I feel like the extra latency is just the web server prepping for the request, and not caused by the site your checking. By cache, are you referring to the cert pool above that I posted? My intention is to have this in main() before the web server starts instead of using time from the first request to prep. Like I said, I am super new at golang, so if I'm missing something just let me know! Appreciate it. |
I changed to code to allow system cert to be added at the start (see |
I noticed when InsecureSkipVerify is set to false, only the first request is verified and takes extra time for the TLSHandshake. Every request after is the same regardless of InsecureSkipVerify value.
Are you having the same issue?
The text was updated successfully, but these errors were encountered: