diff --git a/peer.go b/peer.go index 5518d4e8..33cee2ae 100644 --- a/peer.go +++ b/peer.go @@ -48,8 +48,8 @@ const ( // a buffered channel which will be sent upon once the write is complete. This // buffered channel acts as a semaphore to be used for synchronization purposes. type outgoinMsg struct { - msg lnwire.Message - sentChan chan struct{} // MUST be buffered. + msg lnwire.Message + errChan chan error // MUST be buffered. } // newChannelMsg packages a lnwallet.LightningChannel with a channel that @@ -1027,8 +1027,8 @@ out: // callers to optionally synchronize sends with the // writeHandler. err := p.writeMessage(outMsg.msg) - if outMsg.sentChan != nil { - close(outMsg.sentChan) + if outMsg.errChan != nil { + outMsg.errChan <- err } if err != nil { @@ -1122,12 +1122,17 @@ func (p *peer) PingTime() int64 { } // queueMsg queues a new lnwire.Message to be eventually sent out on the -// wire. -func (p *peer) queueMsg(msg lnwire.Message, doneChan chan struct{}) { +// wire. It returns an error if we failed to queue the message. An error +// is sent on errChan if the message fails being sent to the peer, or +// nil otherwise. +func (p *peer) queueMsg(msg lnwire.Message, errChan chan error) { select { - case p.outgoingQueue <- outgoinMsg{msg, doneChan}: + case p.outgoingQueue <- outgoinMsg{msg, errChan}: case <-p.quit: - return + peerLog.Debugf("Peer shutting down, could not enqueue msg.") + if errChan != nil { + errChan <- fmt.Errorf("peer shutting down") + } } }