sdbusplus: Avoid delay in reading pending i/o
Patch Tracking Bug: b/312751558
Upstream info / review:
https://gerrit.openbmc.org/c/openbmc/sdbusplus/+/67629
Upstream-Status: Accepted
Justification:
The patch was just merged upstream. We need it now to fix b/311232608
since it can cause stateful bmcweb to hang.
Cherry-pick in a patch merged from upstream. It handles an edge case
where if i/o is pending on a socket before the io_context loop is run
then the pending i/o is not read until a new i/o operation is made.
Tested:
Queries to bmcweb still return as expected.
Google-Bug-Id: 311232608
Google-Bug-Id: 312751558
Change-Id: Iee56713081d17dafe69968b205fea5858f9905c9
Signed-off-by: Carson Labrado <clabrado@google.com>
diff --git a/recipes-extended/sdbusplus/sdbusplus/0001-asio-Avoid-delay-in-reading-pending-i-o.patch b/recipes-extended/sdbusplus/sdbusplus/0001-asio-Avoid-delay-in-reading-pending-i-o.patch
new file mode 100644
index 0000000..cba8ceb
--- /dev/null
+++ b/recipes-extended/sdbusplus/sdbusplus/0001-asio-Avoid-delay-in-reading-pending-i-o.patch
@@ -0,0 +1,54 @@
+From 894d6ca45e8c6e095176809bfaf203637bd34c96 Mon Sep 17 00:00:00 2001
+From: Rahul Kapoor <rahulkpr@google.com>
+Date: Tue, 21 Nov 2023 20:05:27 +0000
+Subject: [PATCH] asio: Avoid delay in reading pending i/o
+
+Patch Tracking Bug: b/312751558
+Upstream info / review: go/obmccl/67629
+Upstream-Status: Accepted
+Justification:
+The patch was just merged upstream. We need it now to fix b/311232608
+since it can cause stateful bmcweb to hang.
+
+In a scenario where i/o is pending on socket before io_context loop is
+run, the current implementation does not read the pending i/o when io
+loop starts. When another i/o operation queues up after i/o loop has
+started, the previous pending i/o is read. This delay in reading i/o can
+be avoided by inoking read_immediate() in connection constructor instead
+of read_wait().
+
+A real world use case is
+https://github.com/openbmc/bmcweb/blob/7a696974d7a987e3eb135a6cbad0a4ace8d109d2/src/webserver_main.cpp#L92
+where in RedfishAggregator instantiation, GetManagedObjects to
+entity-manager returns before io_context loop kicks off and the callback
+never invokes until a new async_method_call queues a response which then
+invokes the long pending RedfishAggregator callback.
+
+Change-Id: I4e2d1b407e96c7a4078cd7bd90443699ba0d6623
+Signed-off-by: Rahul Kapoor <rahulkpr@google.com>
+---
+ include/sdbusplus/asio/connection.hpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/include/sdbusplus/asio/connection.hpp b/include/sdbusplus/asio/connection.hpp
+index 62514ab..841c6d7 100644
+--- a/include/sdbusplus/asio/connection.hpp
++++ b/include/sdbusplus/asio/connection.hpp
+@@ -56,12 +56,12 @@ class connection : public sdbusplus::bus_t
+ sdbusplus::bus_t(sdbusplus::bus::new_default()), io_(io),
+ socket(io_.get_executor(), get_fd())
+ {
+- read_wait();
++ read_immediate();
+ }
+ connection(boost::asio::io_context& io, sd_bus* bus) :
+ sdbusplus::bus_t(bus), io_(io), socket(io_.get_executor(), get_fd())
+ {
+- read_wait();
++ read_immediate();
+ }
+ ~connection()
+ {
+--
+2.43.0.rc1.413.gea7ed67945-goog
+
diff --git a/recipes-extended/sdbusplus/sdbusplus_%.bbappend b/recipes-extended/sdbusplus/sdbusplus_%.bbappend
new file mode 100644
index 0000000..2b69429
--- /dev/null
+++ b/recipes-extended/sdbusplus/sdbusplus_%.bbappend
@@ -0,0 +1,5 @@
+FILESEXTRAPATHS:prepend:gbmc := "${THISDIR}/${PN}:"
+
+SRC_URI:append:gbmc = " \
+ file://0001-asio-Avoid-delay-in-reading-pending-i-o.patch \
+"