• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
No results for ""
EXPAND ALL

GIVE DOCS FEEDBACK

Shutting down

Read time: 5 minutes
Last edited: Feb 08, 2024

Overview

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

Newer versions of LaunchDarkly SDKs replace users with contexts

A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. Contexts replace another data object in LaunchDarkly: "users." To learn more, read Contexts.

Creating contexts and evaluating flags based on them is supported in the latest major versions of most of our SDKs. For these SDKs, the code samples on this page include the two most recent versions.

Shutting 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. Server-side, client-side, and mobile 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 or Users lists, 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)

Expand .NET (client-side) code sample

To shut down:

client.Dispose();

Android

Expand Android code sample

To shut down:

client.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:

LDClientSDK_Free(client);

Electron

Expand Electron code sample

To shut down:

await client.close();

Flutter

Expand Flutter code sample

To shut down:

await client.close();

To learn more, read close.

iOS

Expand iOS code sample

To shut down:

client.close()

JavaScript

Expand JavaScript code sample

To shut down:

await client.close();

Node.js (client-side)

Expand Node.js (client-side) code sample

To shut down:

await client.close();

React Native

Expand React Native code sample

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

To shut down:

await client.close();

To learn more, read close.

Server-side SDKs

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

.NET (server-side)

Expand .NET (server-side) code sample

Dispose safely shuts down the client instance.

To shut down:

client.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:

LDServerSDK_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:

ldclient:stop_all_instances()
% Stops the default instance
ldclient:stop_instance()
% Stops a named instance
ldclient: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:

client.Close()

Haskell

Expand Haskell code sample

To shut down:

close client

Java

Expand Java code sample

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

To shut down:

client.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:

client.close();

Python

Expand Python code sample

To shut down:

ldclient.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:

client.close

Rust

Expand Rust code sample

To shut down:

client.close();

Edge SDKs

This feature is available in the following edge SDKs:

Cloudflare

Expand Cloudflare code sample

close safely shuts down the client instance:

client.close();

Vercel

Expand Vercel code sample

close safely shuts down the client instance:

client.close();