@@ -146,9 +146,15 @@ func (c *Client) GetCurrentTip() (*Tip, error) {
146146 if err := c .SendMessage (msg ); err != nil {
147147 return nil , err
148148 }
149- tip := <- c .currentTipChan
149+ tip , ok := <- c .currentTipChan
150+ if ! ok {
151+ return nil , protocol .ProtocolShuttingDownError
152+ }
150153 // Clear out intersect result channel to prevent blocking
151- <- c .intersectResultChan
154+ _ , ok = <- c .intersectResultChan
155+ if ! ok {
156+ return nil , protocol .ProtocolShuttingDownError
157+ }
152158 c .wantCurrentTip = false
153159 return & tip , nil
154160}
@@ -171,6 +177,8 @@ func (c *Client) GetAvailableBlockRange(
171177 gotIntersectResult := false
172178 for {
173179 select {
180+ case <- c .DoneChan ():
181+ return start , end , protocol .ProtocolShuttingDownError
174182 case tip := <- c .currentTipChan :
175183 end = tip .Point
176184 c .wantCurrentTip = false
@@ -200,6 +208,8 @@ func (c *Client) GetAvailableBlockRange(
200208 }
201209 for {
202210 select {
211+ case <- c .DoneChan ():
212+ return start , end , protocol .ProtocolShuttingDownError
203213 case tip := <- c .currentTipChan :
204214 end = tip .Point
205215 c .wantCurrentTip = false
@@ -237,7 +247,9 @@ func (c *Client) Sync(intersectPoints []common.Point) error {
237247 if err := c .SendMessage (msg ); err != nil {
238248 return err
239249 }
240- if err := <- c .intersectResultChan ; err != nil {
250+ if err , ok := <- c .intersectResultChan ; ! ok {
251+ return protocol .ProtocolShuttingDownError
252+ } else if err != nil {
241253 return err
242254 }
243255 // Pipeline the initial block requests to speed things up a bit
0 commit comments