diff --git a/services/shhext/requests.go b/services/shhext/requests.go index ec537d0b0..11876e36f 100644 --- a/services/shhext/requests.go +++ b/services/shhext/requests.go @@ -22,11 +22,11 @@ type requestMeta struct { // NewRequestsRegistry creates instance of the RequestsRegistry and returns pointer to it. func NewRequestsRegistry(delay time.Duration) *RequestsRegistry { - return &RequestsRegistry{ - delay: delay, - uidToTopics: map[common.Hash]common.Hash{}, - byTopicsHash: map[common.Hash]requestMeta{}, + r := &RequestsRegistry{ + delay: delay, } + r.Clear() + return r } // RequestsRegistry keeps map for all requests with timestamp when they were made. @@ -73,6 +73,14 @@ func (r *RequestsRegistry) Unregister(uid common.Hash) { } } +// Clear recreates all structures used for caching requests. +func (r *RequestsRegistry) Clear() { + r.mu.Lock() + defer r.mu.Unlock() + r.uidToTopics = map[common.Hash]common.Hash{} + r.byTopicsHash = map[common.Hash]requestMeta{} +} + // topicsToHash returns non-cryptographic hash of the topics. func topicsToHash(topics []whisper.TopicType) common.Hash { hash := fnv.New32() diff --git a/services/shhext/service.go b/services/shhext/service.go index dd6302b97..c6c3b78f1 100644 --- a/services/shhext/service.go +++ b/services/shhext/service.go @@ -302,6 +302,7 @@ func (s *Service) Stop() error { if s.config.EnableLastUsedMonitor { s.lastUsedMonitor.Stop() } + s.requestsRegistry.Clear() s.envelopesMonitor.Stop() s.mailMonitor.Stop() return nil