messaging3: Add comments about not touching "waiters"
authorVolker Lendecke <vl@samba.org>
Fri, 2 May 2014 09:20:40 +0000 (09:20 +0000)
committerVolker Lendecke <vl@samba.org>
Thu, 8 May 2014 07:10:12 +0000 (09:10 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/messages.c

index 065782ac1b49095b64e9c547cc6e3eebee632d16..6a08531f2a86356e9ae63dc2451def8795c931de 100644 (file)
@@ -491,6 +491,14 @@ struct tevent_req *messaging_filtered_read_send(
        state->filter = filter;
        state->private_data = private_data;
 
+       /*
+        * We add ourselves to the "new_waiters" array, not the "waiters"
+        * array. If we are called from within messaging_read_done,
+        * messaging_dispatch_rec will be in an active for-loop on
+        * "waiters". We must be careful not to mess with this array, because
+        * it could mean that a single event is being delivered twice.
+        */
+
        new_waiters_len = talloc_array_length(msg_ctx->new_waiters);
 
        if (new_waiters_len == msg_ctx->num_new_waiters) {
@@ -521,6 +529,14 @@ static void messaging_filtered_read_cleanup(struct tevent_req *req,
 
        tevent_req_set_cleanup_fn(req, NULL);
 
+       /*
+        * Just set the [new_]waiters entry to NULL, be careful not to mess
+        * with the other "waiters" array contents. We are often called from
+        * within "messaging_dispatch_rec", which loops over
+        * "waiters". Messing with the "waiters" array will mess up that
+        * for-loop.
+        */
+
        for (i=0; i<msg_ctx->num_waiters; i++) {
                if (msg_ctx->waiters[i] == req) {
                        msg_ctx->waiters[i] = NULL;