Fix: multiple consumer locking problems
[lttng-tools.git] / src / common / consumer.c
index 0e33bea72e96b4c6a7c35fd82ec9e1cfb9bb82da..c1dadddb3dd08854bffd8eef8cca3e9a76e82bed 100644 (file)
@@ -274,12 +274,19 @@ void consumer_del_stream(struct lttng_consumer_stream *stream)
                uatomic_dec(&relayd->refcount);
                assert(uatomic_read(&relayd->refcount) >= 0);
 
+               /* Closing streams requires to lock the control socket. */
+               pthread_mutex_lock(&relayd->ctrl_sock_mutex);
                ret = relayd_send_close_stream(&relayd->control_sock,
                                stream->relayd_stream_id,
                                stream->next_net_seq_num - 1);
+               pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
                if (ret < 0) {
-                       ERR("Unable to close stream on the relayd. Continuing");
-                       /* Continue here. There is nothing we can do for the relayd.*/
+                       DBG("Unable to close stream on the relayd. Continuing");
+                       /*
+                        * Continue here. There is nothing we can do for the relayd.
+                        * Chances are that the relayd has closed the socket so we just
+                        * continue cleaning up.
+                        */
                }
 
                /* Both conditions are met, we destroy the relayd. */
@@ -434,8 +441,10 @@ end:
 }
 
 /*
- * Add relayd socket to global consumer data hashtable.
+ * Add relayd socket to global consumer data hashtable. RCU read side lock MUST
+ * be acquired before calling this.
  */
+
 int consumer_add_relayd(struct consumer_relayd_sock_pair *relayd)
 {
        int ret = 0;
@@ -447,20 +456,15 @@ int consumer_add_relayd(struct consumer_relayd_sock_pair *relayd)
                goto end;
        }
 
-       rcu_read_lock();
-
        lttng_ht_lookup(consumer_data.relayd_ht,
                        (void *)((unsigned long) relayd->net_seq_idx), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
        if (node != NULL) {
-               rcu_read_unlock();
                /* Relayd already exist. Ignore the insertion */
                goto end;
        }
        lttng_ht_add_unique_ulong(consumer_data.relayd_ht, &relayd->node);
 
-       rcu_read_unlock();
-
 end:
        return ret;
 }
This page took 0.023808 seconds and 4 git commands to generate.