Repository: hyperledger/aries-cloudagent-python

Issue:
Handle Webhook Server Error's Gracefully
When my webhook server throws an exception the ACA-Py agent that posted the webhook seems to get stuck, it will no longer send messages to other agents and I have to restart.

This is the stack trace.

 2021-02-24 15:07:10,539 aries_cloudagent.transport.outbound.manager ERROR >>> Error when posting to: http://172.17.0.1:8052/topic/issue_credential/; Error: (<class 'aries_cloudagent.transport.outbound.base.OutboundTransportError'>, OutboundTransportError('Unexpected response status 500, caused by: Internal Server Error',), <traceback object at 0x7fa26c317b48>); Re-queue failed message ...
dataowner-agent_1         | 2021-02-24 15:07:20,574 aries_cloudagent.transport.outbound.manager ERROR >>> Outbound message failed to deliver, NOT Re-queued.
dataowner-agent_1         | Traceback (most recent call last):
dataowner-agent_1         |   File "/home/indy/.pyenv/versions/3.6.9/lib/python3.6/site-packages/aries_cloudagent/transport/outbound/http.py", line 72, in handle_message
dataowner-agent_1         |     f"Unexpected response status {response.status}, "
dataowner-agent_1         | aries_cloudagent.transport.outbound.base.OutboundTransportError: Unexpected response status 500, caused by: Internal Server Error
dataowner-agent_1         | 2021-02-24 15:07:20,580 aries_cloudagent.transport.outbound.manager ERROR Outbound message could not be delivered to http://172.17.0.1:8052/topic/issue_credential/
dataowner-agent_1         | Traceback (most recent call last):
dataowner-agent_1         |   File "/home/indy/.pyenv/versions/3.6.9/lib/python3.6/site-packages/aries_cloudagent/transport/outbound/http.py", line 72, in handle_message
dataowner-agent_1         |     f"Unexpected response status {response.status}, "
dataowner-agent_1         | aries_cloudagent.transport.outbound.base.OutboundTransportError: Unexpected response status 500, caused by: Internal Server Error
dataowner-agent_1         | 2021-02-24 15:07:20,581 aries_cloudagent.transport.outbound.manager ERROR Exception in outbound queue processing:
dataowner-agent_1         | Traceback (most recent call last):
dataowner-agent_1         |   File "/home/indy/.pyenv/versions/3.6.9/lib/python3.6/site-packages/aries_cloudagent/transport/outbound/manager.py", line 329, in _process_loop
dataowner-agent_1         |     self.handle_not_delivered(queued.context, queued.message)
dataowner-agent_1         |   File "/home/indy/.pyenv/versions/3.6.9/lib/python3.6/site-packages/aries_cloudagent/core/conductor.py", line 389, in handle_not_delivered
dataowner-agent_1         |     self.inbound_transport_manager.return_undelivered(outbound)
dataowner-agent_1         |   File "/home/indy/.pyenv/versions/3.6.9/lib/python3.6/site-packages/aries_cloudagent/transport/inbound/manager.py", line 231, in return_undelivered
dataowner-agent_1         |     self.undelivered_queue.add_message(outbound)
dataowner-agent_1         |   File "/home/indy/.pyenv/versions/3.6.9/lib/python3.6/site-packages/aries_cloudagent/transport/inbound/delivery_queue.py", line 83, in add_message
dataowner-agent_1         |     if msg.target:
dataowner-agent_1         | AttributeError: 'NoneType' object has no attribute 'target'


I realise that my code should also handle these webhook server exceptions better so perhaps this is not a bug at all. But it does feel like ACA-Py should not be taken out of action by something like this.

I haven't dug into it too deeply, so feel free to tell me this is just an issue on my end :)


Discussion:
@shaangill025 - could you please take a look?
> @shaangill025 - could you please take a look?

Looking into it right now.
@wip-abramson I will appreciate it if you can provide more information regarding the exception being thrown by the webhook server. It will help me figure out why outbound_message as None is being passed within ACA-Py.

Resolving patch:
diff --git a/aries_cloudagent/transport/outbound/manager.py b/aries_cloudagent/transport/outbound/manager.py
--- a/aries_cloudagent/transport/outbound/manager.py
+++ b/aries_cloudagent/transport/outbound/manager.py
@@ -340,7 +340,7 @@ async def _process_loop(self):
                             queued.endpoint,
                             exc_info=queued.error,
                         )
-                        if self.handle_not_delivered:
+                        if self.handle_not_delivered and queued.message:
                             self.handle_not_delivered(queued.profile, queued.message)
                     continue  # remove from buffer
 


Test patch: