Bug 101161 - failed RemoveMatch sends error after return (protocol violation)
Summary: failed RemoveMatch sends error after return (protocol violation)
Status: RESOLVED MOVED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.10
Hardware: ARM Linux (All)
: medium normal
Assignee: D-Bus Maintainers
QA Contact: D-Bus Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-24 01:52 UTC by Matthijs van Duin
Modified: 2018-10-12 21:30 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Matthijs van Duin 2017-05-24 01:52:57 UTC
When RemoveMatch fails, it sends a org.freedesktop.DBus.Error.MatchRuleNotFound error after first sending a normal method return. As a result, clients are unable to determine that RemoveMatch failed.

Example:
   ~$ dbus-send --dest=org.freedesktop.DBus --print-reply / org.freedesktop.DBus.RemoveMatch string:""
   method return time=1495590462.736592 sender=org.freedesktop.DBus -> destination=:1.255 serial=3 reply_serial=2

Monitoring the bus while performing the above reveals that an error reply is also sent, but the client of course discards it.

dbus 1.10.18 and 1.11.12 tested
Comment 1 Simon McVittie 2017-05-24 11:09:09 UTC
(In reply to Matthijs van Duin from comment #0)
> When RemoveMatch fails, it sends a
> org.freedesktop.DBus.Error.MatchRuleNotFound error after first sending a
> normal method return. As a result, clients are unable to determine that
> RemoveMatch failed.

That is indeed a bug, although I'm curious why you would ever handle an error from RemoveMatch() (it can't fail unless you remove a match rule that you never successfully added, which is not something that a correct application should ever end up doing).
Comment 2 Matthijs van Duin 2017-05-24 20:16:23 UTC
(In reply to Simon McVittie from comment #1)
> That is indeed a bug, although I'm curious why you would ever handle an
> error from RemoveMatch() (it can't fail unless you remove a match rule that
> you never successfully added, which is not something that a correct
> application should ever end up doing).

It wasn't clear to me from documentation how adding the same rule twice would behave, i.e. whether the last add/remove would take effect or whether they would balance, so I experimented a bit and briefly got rather confused by not getting any errors at all. That's how I bumped into this.

But sure, in practice it isn't hugely important. Failures from RemoveMatch would mostly be useful as indication of application bugs. It also just struck me as odd that a method call could return twice.
Comment 3 Simon McVittie 2017-05-25 12:02:40 UTC
I'd be happy to review a patch if you get round to it before a maintainer does.

I'd also be happy to review a patch to doc/dbus-specification.xml.in (or other relevant documentation) that specified what happens when you add the same rule more than once (I *think* the answer is that nothing special happens, and to remove it you have to call RemoveMatch() the same number of times you called AddMatch(), but please check).
Comment 4 Simon McVittie 2017-05-31 16:33:52 UTC
(In reply to Matthijs van Duin from comment #0)
> When RemoveMatch fails, it sends a
> org.freedesktop.DBus.Error.MatchRuleNotFound error after first sending a
> normal method return. As a result, clients are unable to determine that
> RemoveMatch failed.

This is harder to fix than you might think:

  /* Send the ack before we remove the rule, since the ack is undone
   * on transaction cancel, but rule removal isn't.
   */
  if (!send_ack_reply (connection, transaction,
                       message, error))
    goto failed;

  matchmaker = bus_connection_get_matchmaker (connection);

  if (!bus_matchmaker_remove_rule_by_value (matchmaker, rule, error))
    goto failed;

  bus_match_rule_unref (rule);

  return TRUE;

The problem is that we are trying to carry out the requested operation transactionally: if we can do the whole operation, we want to do so, but if any part of it fails due to lack of memory, we want to not have any side-effects.

What we need to do is to have some way to allocate the required memory to send the successful reply (and perhaps even queue it for sending in the BusTransaction object), but then cancel sending the successful reply in the case where bus_matchmaker_remove_rule_by_value() fails.
Comment 5 GitLab Migration User 2018-10-12 21:30:52 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/dbus/dbus/issues/175.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.