Skip to content

feat: Use Keep-Alive connection to connect to server

Stan Hu requested to merge sh-enable-http-keepalives-part1 into main

Description

Previously every API request to GitLab took extra time to set up a TLS connection with every request. To improve connection reuse, we need to:

  1. Add a custom fetcher for graphql-request since GraphQL calls were not using the agent. This also has the side benefit of adding log messages that measure the latency of each GraphQL request.

  2. Work around an issue identified in https://github.com/microsoft/vscode/issues/173861 where the Connection: keep-alive header does not appear to be sent, even if the agent's keepAlive option is enabled. We manually add this header to every request.

Note that this commit only fixes the case when http.proxySupport is set to off. The default setting (override) needs a special patch for HTTP keepalives to work: !1265 (merged)

How has this been tested?

  1. In VSCode set Settings -> Settings -> enter http:proxysupport.
  2. Set to off.
  3. Close down all your browsers to GitLab.com.
  4. Record all HTTPS traffic going to GitLab.com. If you are using macOS on WiFi, the interface will be en0:
sudo tcpdump -s 0 -w /tmp/gitlab.pcap host gitlab.com

Tip: you can check whether traffic is idle to gitlab.com by running sudo tcpdump -s 0 host gitlab.com first and then hit CTRL-C to stop.

  1. Open VSCode and a GitLab.com project.
  2. As suggested by @msmiley, measure the number of TLS handshakes in the capture:
tshark -r /tmp/gitlab.pcap -Y 'tls.handshake.type == 1 && tls.handshake.extensions_server_name == "gitlab.com"' -T fields -e ip.dst -e tcp.srcport -e tls.handshake.extensions_server_name | sort | uniq -c | wc -l

This number should remain < 10 and not grow over time.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation
  • Chore (Related to CI or Packaging to platforms)
  • Test gap
Edited by Stan Hu

Merge request reports