Remove Ping from api.Connection interface #6400

Merged
merged 2 commits into from Oct 7, 2016

Conversation

Projects
None yet
4 participants
Contributor

mjs commented Oct 7, 2016

As per pre-existing comments, there should only be one way to check whether an API connection is alive. Given that connections now do a great job of checking themselves - the results of which are exposed via
Broken - the Ping method was removed.

This had some bigger-than-expected fallout in the agent code but this can be cleaned up by making a similar change to State (later).

Remove Ping from api.Connection interface
As per pre-existing comments, there should only be one way to check
whether an API connection is alive. Given that connections now do a
great job of checking themselves - the results of which are exposed via
Broken - the Ping method was removed.

This had some bigger-than-expected fallout in the agent code but this
can be cleaned up by making a similar change to State (later).

Don't you dare land this with an interface called "Brokener" :-)

cmd/jujud/util/util.go
- // Ping pings something.
- Ping() error
+// Brokener provides a type that exposes a "broken" channel.
+type Brokener interface {
@wallyworld

wallyworld Oct 7, 2016

Owner

nooooooooooooooooooooooooooooooooooooooo :-( :-( :-( :-(

There has to be a better name

Contributor

mjs commented Oct 7, 2016

$$merge$$

Contributor

jujubot commented Oct 7, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit f093661 into juju:master Oct 7, 2016

@mjs mjs deleted the mjs:remove-api-conn-ping branch Oct 7, 2016

I have mixed feelings about this. On the one hand, it's good to have a single source of "this connection is broken" information. On the other, this seems racy (see comment) and it's useful to have Ping in tests (using pingConn in apiserver seems like a hack, and some of our external code was also using Ping in tests).

+// ConnectionIsDead returns true if the given Breakable is broken.
+var ConnectionIsDead = func(logger loggo.Logger, conn Breakable) bool {
+ select {
+ case <-conn.Broken():
@rogpeppe

rogpeppe Oct 7, 2016

Owner

Isn't this racy? When we get an error, we want to know if that error was fatal. Before this,
we were sure to be able to tell if the connection is actually still active because we made a Ping
call. By making this change, we are relying on the supposition that if we get an error from
an RPC request and the connection is broken a receive from conn.Broken() immediately
afterwards will succeed.

However I can easily see a scenario where that's not the case - if the act of making a request
triggers the network layer to notice that the connection is down, the api.monitor.run method
may take a while to react and the Broken channel will not be closed by the time we
get around to calling ConnectionIsDead.

I think it would be preferable to have an IsBroken method on Conn (as well as Broken) so
that it has the opportunity to synchronously ask (for example) the rpc.Conn whether it thinks it has broken.

@mjs

mjs Oct 9, 2016

Contributor

Ok, fair enough. How about I add IsBroken as suggested and have it check the Broken channel first, and if that succeeds it then tries a ping to be sure and avoid the race?

I disagree that pingConn is a hack. Ping is just an API call like any other. Why should it get a special method on api.Connection? That said, given that this broken your code, there's a risk that it'll break other places too. I might make it exported again given where we are with the 2.0 release.

mjs added a commit to mjs/juju that referenced this pull request Oct 9, 2016

api: Export Connection.Ping again
... and implement a unit test (it was never tested before).

juju#6400/ removed Ping but this was being
used by some external projects.

mjs added a commit to mjs/juju that referenced this pull request Oct 10, 2016

api: Export Connection.Ping again
... and implement a unit test (it was never tested before).

juju#6400/ removed Ping but this was being
used by some external projects.

jujubot added a commit that referenced this pull request Oct 10, 2016

Merge pull request #6410 from mjs/export-api-conn-ping
api: Export Connection.Ping again

... and implement a unit test (it was never tested before).

#6400 removed Ping but this was being used by some external projects.

### QA

Full unit test suite run and examined behaviour of a HA failover to ensure no regressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment