Bug 896 - D-BUS messages lost when auto-activating
Summary: D-BUS messages lost when auto-activating
Status: RESOLVED MOVED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.5
Hardware: All All
: medium normal
Assignee: D-Bus Maintainers
QA Contact: D-Bus Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 52372
  Show dependency treegraph
 
Reported: 2004-07-20 02:57 UTC by Kimmo Hämäläinen
Modified: 2018-10-12 21:03 UTC (History)
8 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Test server and client + .service and .conf files used (10.08 KB, application/octet-stream)
2004-07-20 02:59 UTC, Kimmo Hämäläinen
Details
test server and client + .service file for activating the server (10.10 KB, application/octet-stream)
2004-07-22 00:28 UTC, Kimmo Hämäläinen
Details
fix (2.99 KB, patch)
2004-07-22 08:31 UTC, Olivier Andrieu
Details | Splinter Review
cleaner fix (1.06 KB, patch)
2004-07-22 19:07 UTC, Olivier Andrieu
Details | Splinter Review
new test programs (6.50 KB, application/x-gzip)
2006-03-17 20:44 UTC, Kimmo Hämäläinen
Details
Implement-org.freedesktop.DBus.Peer-for-th.patch (13.58 KB, patch)
2009-03-18 15:30 UTC, Colin Walters
Details | Splinter Review
Have-dbus-send-always-wait-until-message-i.patch (2.60 KB, patch)
2009-03-18 15:31 UTC, Colin Walters
Details | Splinter Review
this version has the new test (15.55 KB, patch)
2009-03-18 15:43 UTC, Colin Walters
Details | Splinter Review
Ignore-EPIPE-on-writes.patch (2.52 KB, patch)
2009-03-18 16:32 UTC, Colin Walters
Details | Splinter Review
ignore sigpipe (2.53 KB, patch)
2009-03-18 16:44 UTC, Colin Walters
Details | Splinter Review
updated version of Michael's patch (3.99 KB, patch)
2009-04-30 05:18 UTC, Dafydd Harries
Details | Splinter Review
failing trace with revents=POLLIN|POLLERR|POLLHUP (2.35 KB, text/plain)
2009-07-10 18:00 UTC, Colin Walters
Details
0001-Bug-896-Avoid-race-conditions-reading-message-from.patch (5.58 KB, patch)
2009-07-10 18:37 UTC, Colin Walters
Details | Splinter Review

Description Kimmo Hämäläinen 2004-07-20 02:57:25 UTC
I made a simple D-BUS server which writes a line into a file when it receives a
message and a client which sends 100 messages to the server with the
auto-activate flag up in every one of them. The server is not initially running
(it's supposed to be activated by the first message). The D-BUS system bus is
used and proper .service and .conf files are installed for the server.

When the client is run, one of the two things happen:
1) D-BUS system bus crashes (the server is not activated).
2) Another(!) D-BUS system bus appears to ps command's listing and the server is
activated, but the server does not receive any of the 100 messages.

In case of 2) happened and the client is run again, the server receives all the
100 messages (but there's still two D-BUS system buses running, according to ps).
Comment 1 Kimmo Hämäläinen 2004-07-20 02:59:04 UTC
Created attachment 497 [details]
Test server and client + .service and .conf files used
Comment 2 Olivier Andrieu 2004-07-20 16:50:38 UTC
Hmm, works fine for me, using current CVS version and testing with the session
bus instead of the system bus.
Comment 3 Kimmo Hämäläinen 2004-07-21 00:02:26 UTC
I tested it again with v0.21 session bus and the same bug is there, so it must
be fixed in the CVS version.
Comment 4 Kimmo Hämäläinen 2004-07-22 00:23:21 UTC
Tested this with D-BUS CVS version (dated 21 Jul 04) and strange things happened
(server not up, session bus running, only 5 messages with auto-activation flag set):

kihamala@mylly:~/dbus-test/act-test-progs$ ./bug_client 
service bug.svc does not exist
message 1 was put into the queue
message 2 was put into the queue
message 3 was put into the queue
message 4 was put into the queue
message 5 was put into the queue
Message sent
kihamala@mylly:~/dbus-test/act-test-progs$ Fd 4 did not have the close-on-exec
flag set!
Fd 5 did not have the close-on-exec flag set!
22758: assertion failed "sitter != NULL" file "dbus-spawn.c" line 244
Error when connecting to the session bus: Disconnected prior to receiving a reply

[1]+  Aborted                 ./dbus-daemon-1 --session --print-address  (wd:
~/dbus-prefix/bin)
(wd now: ~/dbus-test/act-test-progs)

I.e. the session bus crashed. Strange thing is that the bus does not crash if I
comment out line 43 from the client, where I set the auto-activation flag (but
of course does not launch the server either).

I'll attach the source code soon.
Comment 5 Kimmo Hämäläinen 2004-07-22 00:28:28 UTC
Created attachment 511 [details]
test server and client + .service file for activating the server


client resided in:
/home/kihamala/dbus-test/act-test-progs
server resided in (as specified in .service file):
/home/kihamala/dbus-test
D-BUS daemon (CVS version 21th Jul 04) resided in:
/home/kihamala/dbus-prefix/bin

Ldd output for bug_client:
kihamala@mylly:~/dbus-test/act-test-progs$ ldd bug_client
	libdbus-1.so.0 => /home/kihamala/dbus-prefix/lib/libdbus-1.so.0
(0x40018000)
	libdbus-glib-1.so.0 =>
/home/kihamala/dbus-prefix/lib/libdbus-glib-1.so.0 (0x4007c000)
	libc.so.6 => /lib/libc.so.6 (0x40092000)
	libnsl.so.1 => /lib/libnsl.so.1 (0x401c6000)
	libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x401db000)
	libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x40214000)
	/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
Comment 6 Olivier Andrieu 2004-07-22 08:26:56 UTC
OK, there are several issues. 

First, we have the same problem as bug #894 , ie the daemon loses the last
messages when the client exits. 

As for the assertion failure, here comes a patch.

Then, about the message loss, what's happenning is that, by the time the server
has spawn, registered with bus and acquired its service, the client has exited.
The problem is that in the case of auto-activation message, policy checking is
delayed until the server is up. So when the daemon wants to send the delayed
messages with the auto-activation flag, the client connection is dead, so it
cannot check the policy and it just bins these messages.
Comment 7 Olivier Andrieu 2004-07-22 08:31:23 UTC
Created attachment 512 [details] [review]
fix

first hunk is a cheap optimization, second hunk fixes the bug
Comment 8 Olivier Andrieu 2004-07-22 19:07:50 UTC
Created attachment 518 [details] [review]
cleaner fix

Basically, ignore the HANGUP condition
Comment 9 Olivier Andrieu 2004-07-22 19:14:16 UTC
#$%!£ I posted in the wrong bug. Sorry, that's for bug #894
Comment 10 Kimmo Hämäläinen 2004-07-27 05:53:58 UTC
Comment on attachment 518 [details]