Shutting down

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

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

.NET (client-side)

To shut down:

C#
1client.Dispose();

Android

To shut down:

1client.close();

C++ (client-side)

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

To shut down:

JavaScript
1await client.close();

Flutter

To shut down:

Dart
1await client.close();

To learn more, read close.

iOS

To shut down:

1client.close()

JavaScript

To shut down:

JavaScript
1await client.close();

Node.js (client-side)

To shut down:

JavaScript
1await client.close();

React Native

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

To shut down:

1await client.close();

To learn more, read close.

Server-side SDKs

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

.NET (server-side)

Dispose safely shuts down the client instance.

To shut down:

C#
1client.Dispose();

C++ (server-side)

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

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

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

To shut down:

Go
1client.Close()

Haskell

To shut down:

Haskell
1close client

Java

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)

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

To shut down:

Python
1ldclient.get().close()

Ruby

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

To shut down:

Rust
1client.close();

Edge SDKs

This feature is available in the following edge SDKs:

Cloudflare

close safely shuts down the client instance:

TypeScript
1client.close();

Vercel

close safely shuts down the client instance:

TypeScript
1client.close();
Built with