mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
whisper: Exit api.run when whisper is stopped
This commit is contained in:
parent
5cf75a30c1
commit
c15bf122e4
2 changed files with 28 additions and 20 deletions
|
|
@ -69,20 +69,24 @@ func NewPublicWhisperAPI(w *Whisper) *PublicWhisperAPI {
|
||||||
// this loop deletes filter that have not been used within filterTimeout
|
// this loop deletes filter that have not been used within filterTimeout
|
||||||
func (api *PublicWhisperAPI) run() {
|
func (api *PublicWhisperAPI) run() {
|
||||||
timeout := time.NewTicker(2 * time.Minute)
|
timeout := time.NewTicker(2 * time.Minute)
|
||||||
|
defer timeout.Stop()
|
||||||
for {
|
for {
|
||||||
<-timeout.C
|
select {
|
||||||
|
case <-api.w.quit:
|
||||||
api.mu.Lock()
|
return
|
||||||
for id, lastUsed := range api.lastUsed {
|
case <-timeout.C:
|
||||||
if time.Since(lastUsed).Seconds() >= filterTimeout {
|
api.mu.Lock()
|
||||||
delete(api.lastUsed, id)
|
for id, lastUsed := range api.lastUsed {
|
||||||
if err := api.w.Unsubscribe(id); err != nil {
|
if time.Since(lastUsed).Seconds() >= filterTimeout {
|
||||||
log.Error("could not unsubscribe whisper filter", "error", err)
|
delete(api.lastUsed, id)
|
||||||
|
if err := api.w.Unsubscribe(id); err != nil {
|
||||||
|
log.Error("could not unsubscribe whisper filter", "error", err)
|
||||||
|
}
|
||||||
|
log.Debug("delete whisper filter (timeout)", "id", id)
|
||||||
}
|
}
|
||||||
log.Debug("delete whisper filter (timeout)", "id", id)
|
|
||||||
}
|
}
|
||||||
|
api.mu.Unlock()
|
||||||
}
|
}
|
||||||
api.mu.Unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,20 +70,24 @@ func NewPublicWhisperAPI(w *Whisper) *PublicWhisperAPI {
|
||||||
// this loop deletes filter that have not been used within filterTimeout
|
// this loop deletes filter that have not been used within filterTimeout
|
||||||
func (api *PublicWhisperAPI) run() {
|
func (api *PublicWhisperAPI) run() {
|
||||||
timeout := time.NewTicker(2 * time.Minute)
|
timeout := time.NewTicker(2 * time.Minute)
|
||||||
|
defer timeout.Stop()
|
||||||
for {
|
for {
|
||||||
<-timeout.C
|
select {
|
||||||
|
case <-api.w.quit:
|
||||||
api.mu.Lock()
|
return
|
||||||
for id, lastUsed := range api.lastUsed {
|
case <-timeout.C:
|
||||||
if time.Since(lastUsed).Seconds() >= filterTimeout {
|
api.mu.Lock()
|
||||||
delete(api.lastUsed, id)
|
for id, lastUsed := range api.lastUsed {
|
||||||
if err := api.w.Unsubscribe(id); err != nil {
|
if time.Since(lastUsed).Seconds() >= filterTimeout {
|
||||||
log.Error("could not unsubscribe whisper filter", "error", err)
|
delete(api.lastUsed, id)
|
||||||
|
if err := api.w.Unsubscribe(id); err != nil {
|
||||||
|
log.Error("could not unsubscribe whisper filter", "error", err)
|
||||||
|
}
|
||||||
|
log.Debug("delete whisper filter (timeout)", "id", id)
|
||||||
}
|
}
|
||||||
log.Debug("delete whisper filter (timeout)", "id", id)
|
|
||||||
}
|
}
|
||||||
|
api.mu.Unlock()
|
||||||
}
|
}
|
||||||
api.mu.Unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue