Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Let ConnectionMaker report the reason the connection broke
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Apr 13, 2015
1 parent f8ec56e commit 397cb3b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion router/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (conn *LocalConnection) shutdown(err error) {
// try to send any more
conn.stopForwarders()

conn.Router.ConnectionMaker.ConnectionTerminated(conn.remoteTCPAddr)
conn.Router.ConnectionMaker.ConnectionTerminated(conn.remoteTCPAddr, err)
}

// Helpers
Expand Down
16 changes: 10 additions & 6 deletions router/connection_maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ConnectionMaker struct {
// Information about an address where we may find a peer
type Target struct {
attempting bool // are we currently attempting to connect there?
lastError error // reason for disconnection last time
tryAfter time.Time // next time to try this address
tryInterval time.Duration // backoff time on next failure
}
Expand Down Expand Up @@ -64,10 +65,11 @@ func (cm *ConnectionMaker) ForgetConnection(address string) {
}
}

func (cm *ConnectionMaker) ConnectionTerminated(address string) {
func (cm *ConnectionMaker) ConnectionTerminated(address string, err error) {
cm.actionChan <- func() bool {
if target, found := cm.targets[address]; found {
target.attempting = false
target.lastError = err
target.tryAfter, target.tryInterval = tryAfter(target.tryInterval)
}
return true
Expand All @@ -89,13 +91,15 @@ func (cm *ConnectionMaker) String() string {
cm.actionChan <- func() bool {
var buf bytes.Buffer
for address, target := range cm.targets {
var fmtStr string
fmt.Fprint(&buf, address)
if target.lastError != nil {
fmt.Fprintf(&buf, " (%s)", target.lastError)
}
if target.attempting {
fmtStr = "%s (trying since %v)\n"
fmt.Fprintf(&buf, " (trying since %v)\n", target.tryAfter)
} else {
fmtStr = "%s (next try at %v)\n"
fmt.Fprintf(&buf, "(next try at %v)\n", target.tryAfter)
}
fmt.Fprintf(&buf, fmtStr, address, target.tryAfter)
}
resultChan <- buf.String()
return false
Expand Down Expand Up @@ -201,7 +205,7 @@ func (cm *ConnectionMaker) attemptConnection(address string, acceptNewPeer bool)
log.Printf("->[%s] attempting connection\n", address)
if err := cm.ourself.CreateConnection(address, acceptNewPeer); err != nil {
log.Printf("->[%s] error during connection attempt: %v\n", address, err)
cm.ConnectionTerminated(address)
cm.ConnectionTerminated(address, err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions site/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ broadcast:
7a:f4:56:87:76:3b -> [7a:16:dd:5b:83:de]
7a:16:dd:5b:83:de -> []
Reconnects:
192.168.32.1:6783 (next try at 2014-10-23 16:39:50.585932102 +0000 UTC)
192.168.32.1:6783 (dial tcp4 192.168.32.1:6783: connection timed out) (next try at 2014-10-23 16:39:50.585932102 +0000 UTC)
weavedns container is not present; have you launched it?
````
Expand Down Expand Up @@ -121,8 +121,8 @@ for a full explanation.

The 'Reconnects' section lists peers that this router is aware of, but is
not currently connected to. Each line contains some information about
whether it is attempting to connect or is waiting for a while before
connecting again.
what went wrong the last time; whether it is attempting to connect or
is waiting for a while before connecting again.

Finally, status information from weave DNS is included. In this example,
the DNS container has not been launched so no status information is
Expand Down

0 comments on commit 397cb3b

Please sign in to comment.