Skip to content
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

Memory Leak in Go SDK #466

Closed
6 of 10 tasks
Zach-Johnson opened this issue Jan 13, 2025 · 1 comment
Closed
6 of 10 tasks

Memory Leak in Go SDK #466

Zach-Johnson opened this issue Jan 13, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Zach-Johnson
Copy link

Checklist

  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Slack Community and have not found a suitable solution or answer.
  • I agree to the terms within the OpenFGA Code of Conduct.

Description

There is a memory leak in the Go SDK that occurs when not specifying any telemetry configuration in the client creation, i.e.

		client := openfga.NewAPIClient(&openfga.Configuration{
			HTTPClient: &http.Client{Timeout: 10 * time.Second, Transport: otelhttp.NewTransport(http.DefaultTransport)},
			ApiUrl:     cfg.APIURL,
		})

This happens from this function -

func Get(factory TelemetryFactoryParameters) *Telemetry {
	configuration := factory.Configuration

	if configuration == nil {
		configuration = DefaultTelemetryConfiguration()
	}

	telemetryInstancesLock.Lock()
	defer telemetryInstancesLock.Unlock()

	if TelemetryInstances == nil {
		TelemetryInstances = make(map[*Configuration]*Telemetry)
	}

	if _, exists := TelemetryInstances[configuration]; !exists {
		telemetry, _ := Configure(configuration)
		TelemetryInstances[configuration] = telemetry
	}

	return TelemetryInstances[configuration]
}

Because the configuration on the passed in factory is always nil, the configuration always initializes a new DefaultTelemetryConfiguration which results in a newly allocated pointer. The existence check on the map farther down in that function never finds the same value in the map since the pointer is always different, and allocates a new config in the map. The map grows unbounded.

Expectation

I expect no memory leaks for a valid configuration, or a failure to initialize the client because of an invalid configuration.

Reproduction

Create a client with no telemetry config, make an API call, check a debugger and observe the telemetry map growing unbounded.

SDK Checklist

  • JS SDK
  • Go SDK
  • .NET SDK
  • Python SDK
  • Java SDK

OpenFGA SDK version

v0.6.3

OpenFGA version

v.1.5.5

SDK Configuration

Given above

Logs

No response

References

No response

@ewanharris
Copy link
Member

Closing as we released this in v0.6.4, thanks for the report @Zach-Johnson!

@github-project-automation github-project-automation bot moved this from Backlog to Done in SDKs and Tooling Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants