-
Notifications
You must be signed in to change notification settings - Fork 97
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
dex: redesign ConnectionMaster #1474
Conversation
if !c.On() { | ||
return // probably a bug in the consumer | ||
} | ||
c.cancel() |
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.
See the old Disconnect
method where the cancel
field has always been ungaurded by the mutex.
Evidently we do have sane Connect/Disconnect access patterns, and the On
method is the only one that really needs concurrency controls, which it gets via Done
.
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.
This must not be used before or concurrently with Connect.
I think this is an assumption we are under at various levels. Good to doc it, though.
c.wg.Wait() | ||
c.cancel() // if not called from Disconnect, would leak context |
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.
The WaitGroup
is no longer a field with the new design around the done
channel, but it's worth noting that the old Wait
method did not guard access to either of these fields.
Again, On
appears to be the only method called without any synchronization with the other methods (see (*xcWallet).state
for example).
func (c *ConnectionMaster) On() bool { | ||
select { | ||
case <-c.Done(): | ||
return false |
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.
Although Wait
has the same semantics as before, the On
method now correlates to the Wait
method's timing instead of just when the inner context is canceled. This new way is actually a bit more consistent since depending on how the Connector died (context canceled vs. internally-initiated shutdown) On
would previously indicate slightly different stages of the Connector
's lifecycle (signaled to shut down vs actually shut down).
1d6c118
to
27b4d6a
Compare
Out of draft now since we keep running into issues and I'd kinda like to eliminate the fields that can be nil. #1602 (comment), #1616, #1472 (comment), 6aaa3c0, etc. However, I suspect we still need to rethink the behavior of the Connect(ctx context.Context) (*sync.WaitGroup, error) Seems straightforward, but to facilitate the reconnect loop starting for DEX conns that fail their initial attempt, we have the case where |
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.
Connect(ctx context.Context) (*sync.WaitGroup, error)
could be updated to Connect(ctx context.Context) (*sync.WaitGroup, bool, error)
where if the boolean is true, it means that the the initial connection failed, but the reconnect loop is running.
That's a possibility. I guess the suggestion is to have err be nil in that case, where previously it was whatever error from the initial failed conn attempt? In that case I suppose the logger for whatever subsystem that is could log the error, although that could be suboptimal if we wanna convey the cause to the frontend via a notification or something. |
Kinda seems like we need different behavior depending on whether we are trying the connection for the first time ( |
BTW I've had thoughts about changing the None of this seems high priority though compared to the mess with LTC |
See the discussion at #1445 (comment) for the motivation.
This redesigns
dex.ConnectionMaster
, adding aDone() <-chan struct{}
method upon which theOn
andWait
methods are now based.This also uses the new
Done
method in(*Core).startWalletSyncMonitor
to quit if the wallet shuts down without an extra goroutine sitting onWait
.