For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inTry it free
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
  • SDKs
    • SDK concepts
    • SDK features
      • Aliasing users
      • Anonymous contexts and users
      • Automatic environment attributes
      • Big segments
      • Bootstrapping
      • Caching contexts to local storage
      • Configuration
      • Context configuration
      • Customizing AgentControl
      • Data saving mode
      • Evaluating flags
      • Flag evaluation reasons
      • Flushing events
      • Getting all flags
      • Hooks
      • Identifying and changing contexts
      • Inspectors
      • Logging configuration
      • Migrations
      • Monitoring SDK status
      • Multiple environments
      • Offline mode
      • OpenTelemetry in server-side SDKs
      • Private attributes
      • User feedback
      • Reading flags from a file
      • Relay Proxy configuration
      • Secure mode
      • Sending custom events
      • Shutting down
      • Storing data
      • Subscribing to flag changes
      • Test data sources
      • Tracking AI metrics
      • Web proxy configuration
    • Client-side SDKs
    • Server-side SDKs
    • AI SDKs
    • Edge SDKs
    • OpenFeature providers
    • Observability SDKs
    • Relay Proxy
Sign inTry it free
LogoLogo
On this page
  • Overview
  • Shut down the LaunchDarkly client
  • Client-side SDKs
  • .NET (client-side)
  • Android
  • C++ (client-side)
  • Electron
  • Flutter
  • iOS
  • JavaScript
  • Node.js (client-side)
  • React Native
  • Server-side SDKs
  • .NET (server-side)
  • C++ (server-side)
  • Erlang
  • Go
  • Haskell
  • Java
  • Node.js (server-side)
  • Python
  • Ruby
  • Rust
  • Edge SDKs
  • Cloudflare
  • Fastly
  • Vercel
SDKsSDK features

Shutting down

Was this page helpful?
Previous

Storing data

Next
Built with

Overview

This topic explains how to safely shut down different LaunchDarkly SDKs. This feature is available for client-side, server-side, and edge SDKs.

Shut down the LaunchDarkly client

LaunchDarkly SDKs provide language-specific methods to shut down their instances safely.

In most applications, you do not have to manually shut down an SDK. LaunchDarkly SDKs automatically flush pending analytics events to LaunchDarkly at regular intervals.

However, when your application is about to terminate, you should shut down the LaunchDarkly client. For most SDKs, this ensures that the client releases any resources it is using, and that it delivers any pending analytics to LaunchDarkly. If your application terminates without this shutdown step, flag evaluations and contexts or users may not appear on the Contexts list, because they are derived from analytics events. To learn more, read Analytics events.

Do not attempt to evaluate flags or otherwise use the LaunchDarkly client after it has shut down, as doing so may result in undefined behavior. Shut down the client at a point in your application’s lifecycle where the client is no longer needed.

Details about each SDK’s configuration are available in the SDK-specific sections below.

  • Client-side SDKs
  • Server-side SDKs
  • Edge SDKs

Client-side SDKs

This feature is available in the following client-side SDKs:

  • .NET (client-side)
  • Android
  • C++ (client-side)
  • Electron
  • Flutter
  • iOS
  • JavaScript
  • Node.js (client-side)
  • React Native

.NET (client-side)

Expand .NET (client-side) code sample

To shut down:

C#
1client.Dispose();

Android

Expand Android code sample

To shut down:

1client.close();

C++ (client-side)

Expand C++ (client-side) code sample

In the C++ SDK v3.0, the client will be automatically closed.

If you are using the C binding, you must specifically close the client. The operation blocks until all resources are free.

To shut down:

1LDClientSDK_Free(client);

Electron

Expand Electron code sample

To shut down:

JavaScript
1await client.close();

Flutter

Expand Flutter code sample

To shut down:

Dart
1await client.close();

To learn more, read close.

iOS

Expand iOS code sample

To shut down:

1client.close()

JavaScript

Expand JavaScript code sample

To shut down:

JavaScript
1await client.close();

Node.js (client-side)

Expand Node.js (client-side) code sample

To shut down:

JavaScript
1await client.close();

React Native

Expand React Native code sample

Calling close flushes all queued events and shuts all open network connections.

To shut down:

React Native SDK, v10
1await client.close();

To learn more, read close.

Server-side SDKs

This feature is available in the following server-side SDKs:

  • .NET (server-side)
  • C++ (server-side)
  • Erlang
  • Go
  • Haskell
  • Java
  • Node.js (server-side)
  • Python
  • Ruby
  • Rust

.NET (server-side)

Expand .NET (server-side) code sample

Dispose safely shuts down the client instance.

To shut down:

C#
1client.Dispose();

C++ (server-side)

Expand C++ (server-side) code sample

In the C++ SDK v3.0, the SDK will be automatically closed.

If you are using the C binding, you must specifically close the client. The operation blocks until all resources are free.

To shut down:

1LDServerSDK_Free(client);

Erlang

Expand Erlang code sample

stop_instance(), stop_instance(Tag), and stop_all_instances() all safely shut down client instances and release the resources associated with them.

To shut down:

Erlang
1ldclient:stop_all_instances()
2
3% Stops the default instance
4ldclient:stop_instance()
5
6% Stops a named instance
7ldclient:stop_instance(my_instance)

Go

Expand Go code sample

When your application is about to terminate, shut down the LDClient with Close().

To shut down:

Go
1client.Close()

Haskell

Expand Haskell code sample

To shut down:

Haskell
1close client

Java

Expand Java code sample

Close safely shuts down the client instance and releases all resources associated with the client.

To shut down:

Java
1client.close();

Node.js (server-side)

Expand Node.js (server-side) code sample

Unlike other LaunchDarkly SDKs, the Node.js (server-side) SDK does not automatically send pending analytics events to LaunchDarkly when it shuts down. To send analytics events, you first need to call flush.

To shut down:

JavaScript
1client.close();

Python

Expand Python code sample

To shut down:

Python
1ldclient.get().close()

Ruby

Expand Ruby code sample

Shutting down frees the resources the worker threads were using and provides an explicit signal for the Ruby SDK to send the remaining event data back to LaunchDarkly.

To shut down:

Ruby
1client.close

Rust

Expand Rust code sample

To shut down:

Rust
1client.close();

Edge SDKs

This feature is available in the following edge SDKs:

  • Cloudflare
  • Fastly
  • Vercel

Cloudflare

Expand Cloudflare code sample

close safely shuts down the client instance:

TypeScript
1client.close();

Fastly

Expand Fastly code sample

close safely shuts down the client instance:

TypeScript
1client.close();

Typically, you do not need to call this method, because the client will close safely when the worker exists. However, you must flush events before your worker exits to ensure that they are sent back to LaunchDarkly.

Vercel

Expand Vercel code sample

close safely shuts down the client instance:

TypeScript
1client.close();