cluster: safeguard consensus not set when calling ID

SwarmConnect on the ipfs connector calls rpc Peers() which
requests IDs for every peer member. If that peer member
is booting, it might get the request after RPC is setup
but before consensus is initialized. In which case
a panic happens. Probability that this happens is small, but still.

Also increase the connect swarms delay to 30 seconds, which
should be a bit longer than the default wait_for_leader timeout,
otherwise we might connect swarms while there's not even a leader.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
This commit is contained in:
Hector Sanjuan 2017-11-15 16:23:22 +01:00
parent a1f1ef15d8
commit a656e45375
2 changed files with 7 additions and 2 deletions

View File

@ -586,7 +586,12 @@ func (c *Cluster) ID() api.ID {
addrs = append(addrs, multiaddrJoin(addr, c.id))
}
peers, _ := c.consensus.Peers()
peers := []peer.ID{}
// This method might get called very early by a remote peer
// and might catch us when consensus is not set
if c.consensus != nil {
peers, _ = c.consensus.Peers()
}
return api.ID{
ID: c.id,

View File

@ -17,7 +17,7 @@ const configKey = "ipfshttp"
const (
DefaultProxyAddr = "/ip4/127.0.0.1/tcp/9095"
DefaultNodeAddr = "/ip4/127.0.0.1/tcp/5001"
DefaultConnectSwarmsDelay = 7 * time.Second
DefaultConnectSwarmsDelay = 30 * time.Second
DefaultProxyReadTimeout = 10 * time.Minute
DefaultProxyReadHeaderTimeout = 5 * time.Second
DefaultProxyWriteTimeout = 10 * time.Minute