messaging3: Fix messaging_read_send/recv
commitd0590eec7e12f2a5ddb9f76365d5547cc3c668c1
authorVolker Lendecke <vl@samba.org>
Tue, 29 Apr 2014 12:14:24 +0000 (29 14:14 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 30 Apr 2014 12:52:08 +0000 (30 14:52 +0200)
tree62781f2fcdc1308675db3e1c02fd373a8c9492d2
parent8117dcd5fb9ecda8ce85c064f0ceb4fda29c8e6f
messaging3: Fix messaging_read_send/recv

messaging_read_send/recv was okay for just one handler in the queue. For
multiple handlers it was pretty broken.

A handler that deletes itself as part of the callback (pretty typical use
case...) drops the message for a subsequent handler that responds to the same
message type. In messaging_dispatch_rec we walk the array, however
messaging_read_cleanup has already changed the array. tevent_req_defer_callback
does not help here: It only defers the callback, it does not defer the cleanup
function.

This also happens when a callback deletes a different handler

A handler that re-installs itself in the callback might get a message twice.

This patch changes the code such that only messaging_dispatch_rec adds records
to msg_ctx->waiters, new waiters are put into a staging area first
(msg_ctx->new_waiters). Also messaging_read_cleanup does not move anything
around in msg_ctx->waiters, it only nulls out itself. messaging_dispatch_rec is
changed to cope with this.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/messages.h
source3/lib/messages.c