Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiuse invitations: Agent unable to respond to messages #3233

Open
antoncuranz opened this issue Sep 15, 2024 · 0 comments
Open

Multiuse invitations: Agent unable to respond to messages #3233

antoncuranz opened this issue Sep 15, 2024 · 0 comments

Comments

@antoncuranz
Copy link

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:

cache = self._profile.inject_or(BaseCache)
if cache:
async with cache.acquire(cache_key) as entry:
if entry.result:
cached = entry.result
receipt.sender_did = cached["sender_did"]
receipt.recipient_did_public = cached["recipient_did_public"]
receipt.recipient_did = cached["recipient_did"]
async with self._profile.session() as session:
connection = await ConnRecord.retrieve_by_id(
session, cached["id"]
)
else:
connection = await self.resolve_inbound_connection(receipt)
if connection:
cache_val = {
"id": connection.connection_id,
"sender_did": receipt.sender_did,
"recipient_did": receipt.recipient_did,
"recipient_did_public": receipt.recipient_did_public,
}
await entry.set_result(cache_val, 3600)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant