No results for ""
EXPAND ALL
  • Home
  • API docs

Shutting down

Read time: 5 minutes
Last edited: May 30, 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.

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)

Expand .NET (client-side) code sample

To shut down:

Android

Expand Android code sample

To shut down:

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:

Electron

Expand Electron code sample

To shut down:

Flutter

Expand Flutter code sample

To shut down:

To learn more, read close.

iOS

Expand iOS code sample

To shut down:

JavaScript

Expand JavaScript code sample

To shut down:

Node.js (client-side)

Expand Node.js (client-side) code sample

To shut down:

React Native

Expand React Native code sample

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

To shut down:

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:

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:

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:

Go

Expand Go code sample

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

To shut down:

Haskell

Expand Haskell code sample

To shut down:

Java

Expand Java code sample

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

To shut down:

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:

Python

Expand Python code sample

To shut down:

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:

Rust

Expand Rust code sample

To shut down:

Edge SDKs

This feature is available in the following edge SDKs:

Cloudflare

Expand Cloudflare code sample

close safely shuts down the client instance:

Vercel

Expand Vercel code sample

close safely shuts down the client instance: