Multiuse invitations: Agent unable to respond to messages
Hello, I recently encountered a bug concerning the use of multiuse invitations:
Let's consider the following scenario involving two Agents, Alice and Bob:
Alice creates a multi-use invitation and sends it to Bob.
After the connection was established, Alice has two connection entries: 1: An active one representing the just established connection to Bob 2: A second one in state „invitation“ for the multi-use invitation
Bob only has one active connection to Alice.
If Bob now sends a message (e.g. a discover-features v2.0 query) to Alice, Alice’s agent complains that the connection is not active and does not reply.
I only used public DIDs for the connections (did:sov:xyz).
As far as I understand, this is due to the connection caching in connections/base_manager.py: https://github.com/hyperledger/aries-cloudagent-python/blob/2d2106ed4253f3ad84148c6fb72fba5833154455/aries_cloudagent/connections/base_manager.py#L969-L990 In find_inbound_connection, Alice caches the invitation connection while connecting to Bob. Once the connection is established, the cache still returns the same result even though there is now an active connection.
I applied a quick fix by only caching the connection if it is not in state "invitation“, which solves this problem.
if connection.state != ConnRecord.State.INVITATION:
await entry.set_result(cache_val, 3600)
But it would probably be better if the cache entry is updated as soon as the connection is established.