SIGN IN SIGN UP

Add defensive callback invocation

We have experienced a `std::bad_function_call` exception [1].
The journal entries are showing
```
Jun 17 15:27:21.985663 bmcwebd[1995]: [http_client.hpp:391] recvMessage() failed: asio.ssl error from https://10.5.10.140:17443/redfish/events
Jun 17 15:27:22.043798 bmcwebd[1995]: [http_client.hpp:391] recvMessage() failed: stale parser from https://10.5.10.140:17443/redfish/events
Jun 17 15:27:22.085644 bmcwebd[1995]: terminate called after throwing an instance of 'std::bad_function_call'
Jun 17 15:27:22.086908 bmcwebd[1995]:   what():  bad_function_call
Jun 17 15:27:22.163520 systemd-coredump[4621]: Process 1995 (bmcwebd) of user 0 terminated abnormally with signal 6/ABRT
```

The matching line is
```
void recvMessage(const std::shared_ptr<ConnectionInfo>& /*self*/,
                 const boost::system::error_code& ec,
                 std::size_t bytesTransferred)
{
    ...
    callback(parser->keep_alive(), connId, res);
    ...
}
```

This would imply that the callback function pointer became null when it
is invoked.

```
void sendNext(bool keepAlive, uint32_t connId)
{
    ...
    conn->callback = nullptr;
    ...
}
```

This may be happening due to the race condition between multiple async
operations where the async call is waiting to be invoked but sendNext is
executed first.

This commit is to make the defensive checking of `callback` function
pointer before invoking like

```
   if (callback) {
      callback(parser->keep_alive(), connId, res);
   }
```

[1] https://en.cppreference.com/cpp/utility/functional/bad_function_call

Change-Id: Ic23e17ea486433e3bb7493e8e3c1e56b1798c8e9
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
M
Myung Bae committed
a74ef929d70b9ebad9ad2c29f8f711594d7cb41b
Parent: 53409fb
Committed by Ed Tanous <ed@tanous.net> on 7/29/2026, 4:27:17 PM