Remove subscription for TerminateAfterRetries policy
Redfish Data Model [1] section 6.42.5.2 and EventDestination schema [2]
specify that the subscription is terminated under the following policy
and the conditions.
DeliveryRetryPolicy:
- `TerminateAfterRetries`:
```
This value shall indicate the subscription is terminated after the
maximum number of retries is reached, specified by the
DeliveryRetryAttempts property in the event service.
```
This implements this policy to delete subscription of the stale client
connections after trying `DeliveryRetryAttempts` when
`DeliveryRetryPolicy == TerminateAfterRetries`.
Tested:
1) Subscription with blocked communication between bmcweb and listener
- Run Redfish Event Listener [3] to subscribe events with
`DeliveryRetryPolicy == TerminateAfterRetries`
- Check the subscription creation
```
curl -k -X GET https://${bmc}/redfish/v1/EventService/Subscriptions/
```
- Generate an event and check the delivery to the listener.
For example,
```
curl -k -X POST https://${bmc}/redfish/v1/EventService/Actions/EventService.SubmitTestEvent
```
- Block the communication between bmcweb and listener
(or modify the listener not to delete the subscription at its exit, and
kill the listener so that its subscription is still alive)
- If the above task is already finished, generate more events and wait
for the sufficient time till `DeliveryRetryAttempts`.
- bmcweb journal log may contain the entries like
```
Sep 20 10:47:55 p10bmc bmcwebd[286]: [ERROR http_client.hpp:444] Maximum number of retries reached. https://9.3.62.209:8080/Redfish-Event-Listener
Sep 20 10:47:55 p10bmc bmcwebd[286]: [ERROR event_service_manager.hpp:1459] Subscription 590587653 is deleted after MaxRetryAttempts
```
- Check the subscription again if the subscription is deleted.
2) Redfish Validator passes
[1] https://www.dmtf.org/sites/default/files/standards/documents/DSP0268_2024.3.html
[2] https://github.com/openbmc/bmcweb/blob/878edd599b1706ec8ffe6c3d81ba7cb3534f6393/redfish-core/schema/dmtf/csdl/EventDestination_v1.xml#L857
[3] https://github.com/DMTF/Redfish-Event-Listener
Change-Id: I6e41288995cbb6e37e17a7ef1be093abb7ce54b9
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 546d92c..b48fc6a 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -841,6 +841,27 @@
// Initialize the pool with a single connection
addConnection();
}
+
+ // Check whether all connections are terminated
+ bool areAllConnectionsTerminated()
+ {
+ if (connections.empty())
+ {
+ BMCWEB_LOG_DEBUG("There are no connections for pool id:{}", id);
+ return false;
+ }
+ for (const auto& conn : connections)
+ {
+ if (conn != nullptr && conn->state != ConnState::terminated)
+ {
+ BMCWEB_LOG_DEBUG(
+ "Not all connections of pool id:{} are terminated", id);
+ return false;
+ }
+ }
+ BMCWEB_LOG_INFO("All connections of pool id:{} are terminated", id);
+ return true;
+ }
};
class HttpClient
@@ -914,5 +935,22 @@
pool.first->second->sendData(std::move(data), destUrl, httpHeader, verb,
resHandler);
}
+
+ // Test whether all connections are terminated (after MaxRetryAttempts)
+ bool isTerminated()
+ {
+ for (const auto& pool : connectionPools)
+ {
+ if (pool.second != nullptr &&
+ !pool.second->areAllConnectionsTerminated())
+ {
+ BMCWEB_LOG_DEBUG(
+ "Not all of client connections are terminated");
+ return false;
+ }
+ }
+ BMCWEB_LOG_DEBUG("All client connections are terminated");
+ return true;
+ }
};
} // namespace crow