Skip to content

Commit

Permalink
fix:memory leak (#1284)
Browse files Browse the repository at this point in the history
Signed-off-by: Tsuyoshi Ushio <[email protected]>
  • Loading branch information
TsuyoshiUshio authored Oct 23, 2020
1 parent bda3664 commit 091d7f8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/scalers/gcp_pub_sub_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (s *pubsubScaler) IsActive(ctx context.Context) (bool, error) {
func (s *pubsubScaler) Close() error {
if s.client != nil {
err := s.client.metricsClient.Close()
s.client = nil
if err != nil {
gcpPubSubLog.Error(err, "error closing StackDriver client")
}
Expand Down Expand Up @@ -147,13 +148,15 @@ func (s *pubsubScaler) GetMetrics(ctx context.Context, metricName string, metric
// GetSubscriptionSize gets the number of messages in a subscription by calling the
// Stackdriver api
func (s *pubsubScaler) GetSubscriptionSize(ctx context.Context) (int64, error) {
client, err := NewStackDriverClient(ctx, s.metadata.credentials)
if err != nil {
return -1, err
if s.client == nil {
client, err := NewStackDriverClient(ctx, s.metadata.credentials)
if err != nil {
return -1, err
}
s.client = client
}
s.client = client

filter := `metric.type="` + pubSubStackDriverMetricName + `" AND resource.labels.subscription_id="` + s.metadata.subscriptionName + `"`

return client.GetMetrics(ctx, filter)
return s.client.GetMetrics(ctx, filter)
}

0 comments on commit 091d7f8

Please sign in to comment.