Fix coredump during subscription
Commit 4b712a29debc1a0860cc04850b262203cad402a5 [1] a bug on missing the
subscription copy from user persistent data when subscription object is
created, and it may cause a bmcweb crash.
Tested:
- Create subscription (e.g. Redfish Event Listener)
- Create a dump
```
curl -k -X POST "https://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData" \
-H "Content-Type: application/json" -d '{"DiagnosticDataType": "Manager"}'
curl: (56) OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 0
```
BMC journal will contain like
```
Oct 14 21:49:20 p10bmc bmcwebd[287]: terminate called after throwing an instance of 'std::bad_weak_ptr'
Oct 14 21:49:20 p10bmc bmcwebd[287]: what(): bad_weak_ptr
Oct 14 21:49:21 p10bmc systemd[1]: bmcweb.service: Main process exited, code=dumped, status=6/ABRT
Oct 14 21:49:21 p10bmc systemd[1]: bmcweb.service: Failed with result 'core-dump'
```
[1] 4b712a29debc1a0860cc04850b262203cad402a5
Change-Id: I58479bb5e1f203fec60ad0971f0c750ab5695f14
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 0d9a68b..f6d36de 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -259,9 +259,10 @@
Subscription(Subscription&&) = delete;
Subscription& operator=(Subscription&&) = delete;
- Subscription(const boost::urls::url_view_base& url,
+ Subscription(const persistent_data::UserSubscription& userSubIn,
+ const boost::urls::url_view_base& url,
boost::asio::io_context& ioc) :
- policy(std::make_shared<crow::ConnectionPolicy>())
+ userSub(userSubIn), policy(std::make_shared<crow::ConnectionPolicy>())
{
userSub.destinationUrl = url;
client.emplace(ioc, policy);
@@ -562,8 +563,7 @@
continue;
}
std::shared_ptr<Subscription> subValue =
- std::make_shared<Subscription>(*url, ioc);
- subValue->userSub = newSub;
+ std::make_shared<Subscription>(newSub, *url, ioc);
subscriptionsMap.insert(std::pair(subValue->userSub.id, subValue));
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index ca1e713..cad410b 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -432,7 +432,8 @@
}
std::shared_ptr<Subscription> subValue =
- std::make_shared<Subscription>(*url, app.ioContext());
+ std::make_shared<Subscription>(
+ persistent_data::UserSubscription{}, *url, app.ioContext());
subValue->userSub.destinationUrl = std::move(*url);