yorkie icon indicating copy to clipboard operation
yorkie copied to clipboard

Remove garbage subscriptions after agent stopped ungracefully

Open umi0410 opened this issue 2 years ago • 3 comments

What would you like to be added:

This issue was introduced in a commit of PR #214. In yorkie/backend/sync/etcd/pubsub.go

// TODO(hackerwins): If the agent is not stopped gracefully, there may
// be garbage subscriptions left. Consider introducing a TTL and
// updating it periodically.

Why is this needed:

I guess if connections don't terminate gracefully, agents won't be able to invoke Coordinator.Unsubscribe() method so there can be some garbage subscriptions.

I opened this issue because this existed in the code as TODO but no issue was written.

umi0410 avatar Aug 16 '21 01:08 umi0410

I'm interested in this issue! :smiley:

umi0410 avatar Aug 16 '21 01:08 umi0410

I wrote some memo to explain this issue.

How to create garbage subscriptions

image

There is one yorkie and two clients subscribing the same document so there is two subscription data in etcd and clients can see there is two users in GNB(Global Navigation Bar).

# First, I set my environment by docker-compose
$ docker-compose -f docker/docker-compose-my-debug.yml up --build
...

# Next, I killed the yorkie container.
$ docker rm -f docker_yorkie_1           
docker_yorkie_1

# Next, I re-run the yorkie container.       
$ docker-compose -f docker/docker-compose-my-debug.yml up --build
...

After removing the container ungracefully, creating the container and refreshing the browsers, we can see there are 4 users and 4 subscriptions now eventhough there is only 2 subscription in real(2 subscriptions are garbage subscriptions). image

This proves grabage subcriptions can exist due to ungraceful shutdown.

Why do I refresh the page?

Actually, I don't have to refresh the page to confirm if there are garbage connections, but it is a little helpful to check it visually. If we don't refresh the page, the number of metadata is correct but there is still garbage subscription data in etcd and these are the real garbage subscriptions.

After yorkie shutdown ungracefully and re-run, a client attaches the document and subscribes it again but with the same user metadata. So if we don't refresh the page, we can only see check whether there is garbage subscriptions by etcd.

umi0410 avatar Aug 21 '21 09:08 umi0410

@hackerwins I examined this issue and am considering how to fix it. Can you suggest me some guides?

umi0410 avatar Aug 21 '21 10:08 umi0410

We replaced etcd-based clusters with sharding-based clusters. So this issue can be closed.

hackerwins avatar Jun 07 '23 11:06 hackerwins