-
Notifications
You must be signed in to change notification settings - Fork 93
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
Reset DefaultPinger to reconnect to server #228
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider what could happen if the connection drops when a ping is scheduled:
c.error
called by something elsepinger
exits with "failed to send PINGREQ" (having calledreset
)c.error
call from step 1 runs and stops the refreshed pinger (meaning that all future calls toRun
will fail).I realise that the above sequence of events is pretty unlikely but I believe it's possible (and it would be pretty hard to trace!). I think it's preferable for the
reset
to happen inRun
meaningRun
will work for a newDefaultPinger
or following a clean shutdown (the user must always wait forRun
to terminate before calling it again). This should be documented in theinterface
to make it clear that thepinger
is reusable.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.
Yes I think that scenario is possible too. I'll think about it more.
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.
@MattBrittan What about adding
Reset()
to Pinger interface like thisand call it right after closing client?
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 problem I see with this is "what should the Pinger do if
Reset()
is called whilst the pinger is running". We may just say "this can't happen" (probably a mistake!) but then there is no real benefit to having a separate function (you can effectively call Reset from withinRun
). If we agree thatRun
could conceivably be called beforeStop
completes then the question becomes "what can you do about it" (only think I can come up with is to stop the old one and log a message).As such I don't think there is much value in adding
Reset
and it's probably simplest/safest ifRun
:Run
is active and, if so:Run
should return an error so it will be logged etc).Run
may need to wait forRun
to terminate.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.
Sorry - ran out of time today so will try to have a look tomorrow.
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.
@MattBrittan No problem.
Are we 100% sure that
Run()
will always be called beforeStop()
?In this scenario,
c.close()
is called right afterc.Connect()
Stop()
is called before callingRun()
in gorutineI think it can be possible because we don't wait for calling
Run()
inc.Connect()
, although it will always never happen.To be 100% sure, then I guess we need to separate
Run()
to things likeStart()
andWait()
like below, so thatc.Connect()
can wait forStart()
of PingHandler.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.
Yep, I had been wondering if it would make more sense to pass
Run
aContext
and use that for termination (was going to mock this up today but ran out of time).