Fix: session_find_by_id can return NULL legitimately
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 9 Mar 2016 20:34:52 +0000 (15:34 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 9 Mar 2016 20:34:52 +0000 (15:34 -0500)
session_find_by_id can return NULL when the backing hash table
is NULL. This is not an error in the context of
its caller, save_per_pid_lost_discarded_counters(), since the
ltt_session can be destroyed before an ust app session is torn down.

See the comment in save_per_pid_lost_discarded_counters() for more
information.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/session.c
src/bin/lttng-sessiond/ust-app.c

index 456901685daeb25a2c28e23df500dc408ea5fcca..5a10340a71ab28d67285010cc7a9e311d4b018e9 100644 (file)
@@ -298,17 +298,21 @@ struct ltt_session *session_find_by_id(uint64_t id)
        struct lttng_ht_iter iter;
        struct ltt_session *ls;
 
+       if (!ltt_sessions_ht_by_id) {
+               goto end;
+       }
+
        lttng_ht_lookup(ltt_sessions_ht_by_id, &id, &iter);
        node = lttng_ht_iter_get_node_u64(&iter);
        if (node == NULL) {
-               goto error;
+               goto end;
        }
        ls = caa_container_of(node, struct ltt_session, node);
 
        DBG3("Session %" PRIu64 " found by id.", id);
        return ls;
 
-error:
+end:
        DBG3("Session %" PRIu64 " NOT found by id", id);
        return NULL;
 }
index 331a9d67160d4fee424e4ddb892e1f7057f8983b..9b634facc1422630827e5e92268839ef37b20146 100644 (file)
@@ -392,12 +392,22 @@ void save_per_pid_lost_discarded_counters(struct ust_app_channel *ua_chan)
 
        rcu_read_lock();
        session = session_find_by_id(ua_chan->session->tracing_id);
-       if (!session) {
-               ERR("Missing LTT session to get discarded events");
-               goto end;
-       }
-       if (!session->ust_session) {
-               ERR("Missing UST session to get discarded events");
+       if (!session || !session->ust_session) {
+               /*
+                * Not finding the session is not an error because there are
+                * multiple ways the channels can be torn down.
+                *
+                * 1) The session daemon can initiate the destruction of the
+                *    ust app session after receiving a destroy command or
+                *    during its shutdown/teardown.
+                * 2) The application, since we are in per-pid tracing, is
+                *    unregistering and tearing down its ust app session.
+                *
+                * Both paths are protected by the session list lock which
+                * ensures that the accounting of lost packets and discarded
+                * events is done exactly once. The session is then unpublished
+                * from the session list, resulting in this condition.
+                */
                goto end;
        }
 
This page took 0.041634 seconds and 4 git commands to generate.