-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Lock watchDocuments depending on the client #479
Conversation
Codecov Report
@@ Coverage Diff @@
## main #479 +/- ##
==========================================
- Coverage 46.56% 46.51% -0.06%
==========================================
Files 69 69
Lines 5788 5805 +17
==========================================
+ Hits 2695 2700 +5
- Misses 2785 2797 +12
Partials 308 308
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution.
I left a few comments.
server/rpc/yorkie_server.go
Outdated
locker, err := s.backend.Coordinator.NewLocker( | ||
stream.Context(), | ||
sync.NewKey(cli.ID.String()), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if err := locker.Lock(stream.Context()); err != nil { | ||
return err | ||
} | ||
|
||
subscription, peersMap, err := s.watchDocs(stream.Context(), *cli, docKeys) | ||
if err != nil { | ||
logging.From(stream.Context()).Error(err) | ||
return err | ||
} | ||
defer func() { | ||
s.unwatchDocs(docKeys, subscription) | ||
if err := locker.Unlock(stream.Context()); err != nil { | ||
logging.DefaultLogger().Error(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
If an error is returned by
s.watchDocs
, releasing the lock is not executed. So, How about movinglocker.Unlock
to just belowlocker.lock
with defer? -
locker.Unlock
may not be executed when the stream is terminated and the context is in the cancel state. How about usingcontext.Background
instead ofstream.Context
? https://pkg.go.dev/context#pkg-overview -
We need to separate the key of the lock with
snapshot-*
orpushpull-*
. How about creating a key with the prefixwatchdocs-*
?
edd2e09
to
d4b6758
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
The event order has been modified to be guaranteed yorkie-team/yorkie#479
What this PR does / why we need it:
If a client requests to attach to multiple documents simultaneously,
the existing connection will be disconnected and reconnected.
Depending on the order of the published events, problems may occur on the client.
If the
watched
event is published before theunwatched
event, the test will failsince the final state is
watched
, but theunwatched
event arrives later.(please refer to the yorkie-js-sdk test).
This image shows the server log when the
watched
event is published first.To resolve this, I added a lock for each client in the
watchDocument
.This ensures that a lock is set when a client establishes a stream and released when the client unwatches.
Which issue(s) this PR fixes:
Fixes yorkie-team/yorkie-js-sdk#464 (comment)
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist: