@@ -154,7 +154,7 @@ func (s *Service) loop() {
154
154
txSub := txpool .SubscribeNewTxsEvent (txEventCh )
155
155
defer txSub .Unsubscribe ()
156
156
157
- // Start a goroutine that exhausts the subsciptions to avoid events piling up
157
+ // Start a goroutine that exhausts the subscriptions to avoid events piling up
158
158
var (
159
159
quitCh = make (chan struct {})
160
160
headCh = make (chan * types.Block , 1 )
@@ -194,16 +194,17 @@ func (s *Service) loop() {
194
194
}
195
195
close (quitCh )
196
196
}()
197
+
198
+ // Resolve the URL, defaulting to TLS, but falling back to none too
199
+ path := fmt .Sprintf ("%s/api" , s .host )
200
+ urls := []string {path }
201
+
202
+ // url.Parse and url.IsAbs is unsuitable (https://github.com/golang/go/issues/19779)
203
+ if ! strings .Contains (path , "://" ) {
204
+ urls = []string {"wss://" + path , "ws://" + path }
205
+ }
197
206
// Loop reporting until termination
198
207
for {
199
- // Resolve the URL, defaulting to TLS, but falling back to none too
200
- path := fmt .Sprintf ("%s/api" , s .host )
201
- urls := []string {path }
202
-
203
- // url.Parse and url.IsAbs is unsuitable (https://github.com/golang/go/issues/19779)
204
- if ! strings .Contains (path , "://" ) {
205
- urls = []string {"wss://" + path , "ws://" + path }
206
- }
207
208
// Establish a websocket connection to the server on any supported URL
208
209
var (
209
210
conn * websocket.Conn
@@ -240,11 +241,12 @@ func (s *Service) loop() {
240
241
}
241
242
// Keep sending status updates until the connection breaks
242
243
fullReport := time .NewTicker (15 * time .Second )
243
- defer fullReport .Stop ()
244
244
245
245
for err == nil {
246
246
select {
247
247
case <- quitCh :
248
+ fullReport .Stop ()
249
+ // Make sure the connection is closed
248
250
conn .Close ()
249
251
return
250
252
@@ -269,6 +271,7 @@ func (s *Service) loop() {
269
271
}
270
272
}
271
273
}
274
+ fullReport .Stop ()
272
275
// Make sure the connection is closed
273
276
conn .Close ()
274
277
}
0 commit comments