func (c *ServiceClient) attemptSend(timeout chan bool, attempts chan sendAttempt, ri *skynet.RequestInfo, fn string, in interface{}) { ts("attemptSend") defer te("attemptSend") // first find an available instance var instance *skynet.ServiceInfo var r pools.Resource var err error for r == nil { var ok bool instance, ok = c.chooser.Choose(timeout) if !ok { dbg("timed out") // must have timed out return } dbg("chose", getInstanceKey(instance)) sp := c.instances[getInstanceKey(instance)] // then, get a connection to that instance dbg("acquiring connection") r, err = sp.pool.Acquire() dbgerr("sp.pool.Acquire", err) dbg("acquired connection") defer sp.pool.Release(r) if err != nil { if r != nil { r.Close() } // TODO: report connection failure c.chooser.Remove(instance) c.Log.Item(FailedConnection{err}) } } if err != nil { c.Log.Item(err) attempts <- sendAttempt{err: err} return } sr := r.(ServiceResource) result, serviceErr, err := c.sendToInstance(sr, ri, fn, in) dbgerr("c.sendToInstance", err) if err != nil { // some communication error happened, shut down this connection and remove it from the pool sr.Close() // and remove the instance from the chooser c.chooser.Remove(instance) return } attempts <- sendAttempt{ result: result, err: serviceErr, } }
func (c *ServiceClient) attemptSend(timeout chan bool, attempts chan sendAttempt, ri *skynet.RequestInfo, fn string, in interface{}) { // first find an available instance var r pools.Resource var err error for r == nil { instance, ok := c.chooser.Choose(timeout) if !ok { // must have timed out return } sp := c.instances[getInstanceKey(instance)] // then, get a connection to that instance r, err = sp.pool.Acquire() defer sp.pool.Release(r) if err != nil { if r != nil { r.Close() } // TODO: report connection failure c.chooser.Remove(instance) c.Log.Item(FailedConnection{err}) } } if err != nil { c.Log.Item(err) attempts <- sendAttempt{err: err} return } sr := r.(ServiceResource) result, err := c.sendToInstance(sr, ri, fn, in) attempts <- sendAttempt{ result: result, err: err, } }