Skip to content

[manager/dispatcher] Synchronize Dispatcher.Stop() with incoming rpcs.#2519

Merged
dperny merged 1 commit intomoby:masterfrom
anshulpundir:dispatcher
Feb 21, 2018
Merged

[manager/dispatcher] Synchronize Dispatcher.Stop() with incoming rpcs.#2519
dperny merged 1 commit intomoby:masterfrom
anshulpundir:dispatcher

Conversation

@anshulpundir
Copy link
Contributor

Fixes for synchronizing the dispatcher shutdown with in-progress rpcs. This addresses the case where the Dispatcher.Register() rpc races with Dispatcher.Stop() and reinserts into the dispatcher node store after it has been cleaned up by Stop().

@anshulpundir anshulpundir force-pushed the dispatcher branch 2 times, most recently from 68bf7b5 to 788dd37 Compare February 21, 2018 00:14
@codecov
Copy link

codecov bot commented Feb 21, 2018

Codecov Report

Merging #2519 into master will increase coverage by 0.01%.
The diff coverage is 85.18%.

@@            Coverage Diff             @@
##           master    #2519      +/-   ##
==========================================
+ Coverage    61.3%   61.31%   +0.01%     
==========================================
  Files         133      133              
  Lines       21710    21724      +14     
==========================================
+ Hits        13309    13320      +11     
- Misses       6948     6962      +14     
+ Partials     1453     1442      -11

@dperny
Copy link
Collaborator

dperny commented Feb 21, 2018

why not combine rpcRW and mu?

d.rpcRW.RLock()
defer d.rpcRW.RUnlock()

if !d.isRunning() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to fail Heartbeat() calls after the d.nodes has been cleared. Should be OK to call without a lock because dispatcher is stopped (basically wanted to prevent grabbing a lock on every Heartbeat)

cc @fcrisciani

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anshulpundir thanks for clarifying. This also needs to be a comment here.

@anshulpundir
Copy link
Contributor Author

why not combine rpcRW and mu?

I have similar sentiments, but trying to keep it simple for now. Also need to get this in by tomorrow @dperny

// Add() with a positive delta that occur when the counter is zero
// must happen before a Wait().
// As is, dispatcher's top() can race with Run().
d.wg.Wait()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anshulpundir what is this waitgroup currently required for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its used in case Stop() is called before the dispatcher Run has a chance to initialize the dispatcher.

@anshulpundir anshulpundir force-pushed the dispatcher branch 2 times, most recently from e694fe2 to 0b5ac34 Compare February 21, 2018 01:25
Copy link
Contributor

@nishanttotla nishanttotla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall structure LGTM.

@anshulpundir I'm okay with combining mu and rpcRW in a follow-up PR, but we should probably do that soon.

@anshulpundir
Copy link
Contributor Author

anshulpundir commented Feb 21, 2018

I'm okay with combining mu and rpcRW in a follow-up PR, but we should probably do that soon.

I have not done an exhaustive analysis on if its actually a good idea to replace mu with rpcRW, or if it actually reduces complexity rather than add to it. So, whether we should do it will probably depend on that. LMK if you are convinced that it should happen and I can definitely prioritize it!

@nishanttotla

@fcrisciani
Copy link

LGTM

// Add() with a positive delta that occur when the counter is zero
// must happen before a Wait().
// As is, dispatcher Stop() can race with Run().
d.wg.Wait()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, what does this waitgroup do now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i hadn't refreshed before i commented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Anshul Pundir <anshul.pundir@docker.com>
@dperny
Copy link
Collaborator

dperny commented Feb 21, 2018

LGTM, will merge when CI goes green.

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

Successfully merging this pull request may close these issues.

4 participants