You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[agent] Cleanup unused, shimmed websocket connections after a configurable timeout.
This PR adds a configurable value for how long shimmed websocket connections can remain idle before they are garbage collected.
Previously, the underlying connection from the proxy agent to the backend server was only cleaned up when there was either an error while sending or receiving messages, or if the agent received an explicit close message.
When a client of shim protocol stopped communicating without first sending a close message, this caused the underlying connection between the proxy agent and backend server to be retained indefinitely. That, in turn, can result in a resource leak within the agent (and possibly in the backend server as well).
To account for that scenario, we needed to find some way to identify that a client of the shim protocol had stopped communicating, so that we could clean up those lost connections.
The shim protocol does not include any sort of ping or pong messages, but it does have polling requests sent by the client which can be used as a dead-man switch; once a sufficient amount of time has elapsed since the last such request, we can assume that the client is gone and the underlying connection can be removed.
This PR adds a configuration option to the agent to specify what that amount of time should be (with a default of 1 hour), and implements the agent-side cleanup logic to identify and close expired connections.
Copy file name to clipboardExpand all lines: agent/agent.go
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -73,6 +73,7 @@ var (
73
73
injectBanner=flag.String("inject-banner", "", "HTML snippet to inject in served webpages")
74
74
bannerHeight=flag.String("banner-height", "40px", "Height of the injected banner. This is ignored if no banner is set.")
75
75
shimWebsockets=flag.Bool("shim-websockets", false, "Whether or not to replace websockets with a shim")
76
+
websocketShimTimeout=flag.Duration("websocket-shim-timeout", 60*time.Minute, "Timeout for websocket shim connections to expire due to inactivity.")
76
77
shimPath=flag.String("shim-path", "", "Path under which to handle websocket shim requests")
77
78
healthCheckPath=flag.String("health-check-path", "/", "Path on backend host to issue health checks against. Defaults to the root.")
78
79
healthCheckFreq=flag.Int("health-check-interval-seconds", 0, "Wait time in seconds between health checks. Set to zero to disable health checks. Checks disabled by default.")
monitoringEndpoint=flag.String("monitoring-endpoint", "staging-monitoring.sandbox.googleapis.com:443", "The endpoint to which to write metrics. Eg: monitoring.googleapis.com corresponds to Cloud Monarch.")
49
50
monitoringResourceType=flag.String("monitoring-resource-type", "gce_instance", "The monitoring resource type. Eg: gce_instance")
50
51
monitoringResourceLabels=flag.String("monitoring-resource-labels", "instance-id=fake-instance-id,instance-zone=us-west1-a", "Comma separated key value pairs for the purpose of monitoring configuration. Eg: 'instance-id=my-instance-id,instance-zone=us-west1-a")
52
+
websocketShimTimeout=flag.Duration("websocket-shim-timeout", 60*time.Minute, "Timeout for websocket shim connections to expire due to inactivity.")
0 commit comments