Skip to content

[ws-proxy] fix leak idle connection cache #20857

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

Merged
merged 1 commit into from
May 28, 2025
Merged

[ws-proxy] fix leak idle connection cache #20857

merged 1 commit into from
May 28, 2025

Conversation

iQQBot
Copy link
Contributor

@iQQBot iQQBot commented May 28, 2025

Description

[ws-proxy] fix leak idle connection cache

Related Issue(s)

Fixes CLC-1392

How to test

  1. start a workspace in preview env
  2. start a simple HTTP server with public visibility, use an unusual port for quick identification. e.g. 28832
  3. ssh into vm
  4. use conntrack -L | grep 28832 for observe
  5. open port URL and refresh many times, it should reuse the connection or close the connection.
image

Documentation

Preview status

Gitpod was successfully deployed to your preview environment.

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment / Integration Tests
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • /werft preemptible
    Saves cost. Untick this only if you're really sure you need a non-preemtible machine.
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh. If enabled, with-preview and with-large-vm will be enabled.
  • with-monitoring

/hold

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR centralizes HTTP transport creation to prevent idle connection leaks by reusing a single transport instance with customizable options.

  • Introduce createDefaultTransport with variadic createHttpTransportOpt and a withSkipTLSVerify option.
  • Replace inline http.Transport instantiation in routes with a reused portTransport.
  • Remove direct tls.Config setup in favor of the new transport option pattern.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
components/ws-proxy/pkg/proxy/routes.go Define and reuse portTransport via createDefaultTransport
components/ws-proxy/pkg/proxy/pass.go Add createHttpTransportOpt, withSkipTLSVerify, and update transport constructor
Comments suppressed due to low confidence (5)

components/ws-proxy/pkg/proxy/pass.go:225

  • [nitpick] Consider renaming 'withSkipTLSVerify' to 'skipTLSVerifyOpt' or similar to align with the 'XxxOpt' naming convention for option functions.
func withSkipTLSVerify() createHttpTransportOpt {

components/ws-proxy/pkg/proxy/pass.go:233

  • There are no unit tests for 'createDefaultTransport' or its options; add tests to verify that 'withSkipTLSVerify' and timeout settings are applied correctly.
func createDefaultTransport(config *TransportConfig, opts ...createHttpTransportOpt) http.RoundTripper {

components/ws-proxy/pkg/proxy/routes.go:534

  • [nitpick] The variable name 'portTransport' may be ambiguous; consider renaming to 'wsPortTransport' or 'defaultPortTransport' to clarify its purpose.
portTransport := createDefaultTransport(config.Config.TransportConfig, withSkipTLSVerify())

components/ws-proxy/pkg/proxy/pass.go:41

  • The comment has grammatical issues; consider rephrasing to 'createHttpTransportOpt allows composing HTTP transport options.'
// createHttpTransportOpt allows to compose create http Transport options.

components/ws-proxy/pkg/proxy/pass.go:233

  • Add a comment describing the parameters of 'createDefaultTransport' and how the variadic options are applied to improve maintainability.
func createDefaultTransport(config *TransportConfig, opts ...createHttpTransportOpt) http.RoundTripper {

@kylos101
Copy link
Contributor

👋 @iQQBot I'll take a look right now

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM ✔️

@geropl
Copy link
Member

geropl commented May 28, 2025

Thank you @iQQBot for crushing once again! 🚀

@iQQBot
Copy link
Contributor Author

iQQBot commented May 28, 2025

/unhold

@roboquat roboquat merged commit 956ee80 into main May 28, 2025
77 of 78 checks passed
@roboquat roboquat deleted the pd/CLC-1392 branch May 28, 2025 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants