dbus: No infinite timeout calls on ChromeOS system daemon
ChromeOS system daemon will be configured to have a max reply
timeout (of 1 hour). Replace `TIMEOUT_INFINITE` in existing
calls with `TIMEOUT_MAX_CHROMEOS` for ChromeOS.
Bug: b:388332345
Change-Id: Ic664ab3047cd396911202e8da6cfd613ce4499a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6261306
Reviewed-by: Ryo Hashimoto <hashimoto@chromium.org>
Reviewed-by: David Padlipsky <dpad@google.com>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Michael Sun <michaelfsun@google.com>
Reviewed-by: Nina Satragno <nsatragno@chromium.org>
Reviewed-by: Igor <igorcov@chromium.org>
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1422528}
NOKEYCHECK=True
GitOrigin-RevId: 2e2f97adb32f3ab6d18e70b7d1421178167cf94c
diff --git a/object_proxy.cc b/object_proxy.cc
index 19ca666..89e706b 100644
--- a/object_proxy.cc
+++ b/object_proxy.cc
@@ -5,8 +5,10 @@
#include "dbus/object_proxy.h"
#include <stddef.h>
+
#include <utility>
+#include "base/check.h"
#include "base/containers/contains.h"
#include "base/debug/alias.h"
#include "base/debug/leak_annotations.h"
@@ -18,6 +20,7 @@
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
+#include "build/build_config.h"
#include "dbus/bus.h"
#include "dbus/dbus_statistics.h"
#include "dbus/error.h"
@@ -132,6 +135,11 @@
ObjectProxy::CallMethodAndBlock(MethodCall* method_call, int timeout_ms) {
bus_->AssertOnDBusThread();
+#if BUILDFLAG(IS_CHROMEOS)
+ // ChromeOS system daemon has `reply_timeout` configured.
+ CHECK_LE(timeout_ms, TIMEOUT_MAX);
+#endif // BUILDFLAG(IS_CHROMEOS)
+
if (!bus_->Connect() || !method_call->SetDestination(service_name_) ||
!method_call->SetPath(object_path_)) {
// Not an error from libdbus, so returns invalid error.
@@ -167,6 +175,11 @@
ResponseOrErrorCallback callback) {
bus_->AssertOnOriginThread();
+#if BUILDFLAG(IS_CHROMEOS)
+ // ChromeOS system daemon has `reply_timeout` configured.
+ CHECK_LE(timeout_ms, TIMEOUT_MAX);
+#endif // BUILDFLAG(IS_CHROMEOS)
+
ReplyCallbackHolder callback_holder(bus_->GetOriginTaskRunner(),
std::move(callback));
diff --git a/object_proxy.h b/object_proxy.h
index 72da3e7..31fddb0 100644
--- a/object_proxy.h
+++ b/object_proxy.h
@@ -62,13 +62,16 @@
};
// Special timeout constants.
- //
- // The constants correspond to DBUS_TIMEOUT_USE_DEFAULT and
- // DBUS_TIMEOUT_INFINITE. Here we use literal numbers instead of these
- // macros as these aren't defined with D-Bus earlier than 1.4.12.
enum {
+ // The constant corresponds to DBUS_TIMEOUT_USE_DEFAULT. Here we use literal
+ // numbers instead of these macros as these aren't defined with D-Bus
+ // earlier than 1.4.12.
TIMEOUT_USE_DEFAULT = -1,
- TIMEOUT_INFINITE = 0x7fffffff,
+
+ // Max timeout for methods calls. Long method calls add to `pending_replies"
+ // in dbus_daemon and it has a limit. Once that limit is exceeded, no more
+ // calls could be made on the relevant DBusConnection.
+ TIMEOUT_MAX = base::Hours(1).InMilliseconds(),
};
// Called when an error response is returned or no response is returned.