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

    EDIT ON GITHUB

    Shutting down

    Read time: 2 minutes
    Last edited: May 17, 2023

    Overview

    This topic explains how to safely shut down different LaunchDarkly SDKs. This feature is available for both client-side and server-side 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 and segments.

    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 an SDK

    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. 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/C++ (client-side)

    Expand C/C++ (client-side) code sample

    To fully uninitialize the C/C++ SDK resources, you must use close. The operation blocks until all resources are free.

    To shut down:

    LDClientClose(client);

    Electron

    Expand Electron code sample

    To shut down:

    await client.close();

    Flutter

    Expand Flutter code sample

    To shut down:

    await LDClient.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

    To shut down:

    await client.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/C++ (server-side)

    Expand C/C++ (server-side) code sample

    LDClientClose uninitializes the resources the C/C++ SDK uses. The operation blocks until all resources are free.

    To shut down:

    LDClientClose(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

    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();