aboutsummaryrefslogtreecommitdiffstats
path: root/eth/filters/filter_system.go
diff options
context:
space:
mode:
authorHenning Diedrich <hd@eonblast.com>2016-06-17 15:53:54 +0800
committerHenning Diedrich <hd@eonblast.com>2016-07-04 23:38:35 +0800
commit51f8ce26cf6dbc20ddc548af305739db981fdd41 (patch)
treeb13008fdb341c2c0f1429069a7935615ff6b8d29 /eth/filters/filter_system.go
parent4f3f6e28d545ffd84a98520347ba6670d80272b5 (diff)
downloadgo-tangerine-51f8ce26cf6dbc20ddc548af305739db981fdd41.tar
go-tangerine-51f8ce26cf6dbc20ddc548af305739db981fdd41.tar.gz
go-tangerine-51f8ce26cf6dbc20ddc548af305739db981fdd41.tar.bz2
go-tangerine-51f8ce26cf6dbc20ddc548af305739db981fdd41.tar.lz
go-tangerine-51f8ce26cf6dbc20ddc548af305739db981fdd41.tar.xz
go-tangerine-51f8ce26cf6dbc20ddc548af305739db981fdd41.tar.zst
go-tangerine-51f8ce26cf6dbc20ddc548af305739db981fdd41.zip
eth: fix #2710 filter races
and locking bugs found in its wake.
Diffstat (limited to 'eth/filters/filter_system.go')
-rw-r--r--eth/filters/filter_system.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go
index 4343dfa21..256464213 100644
--- a/eth/filters/filter_system.go
+++ b/eth/filters/filter_system.go
@@ -82,11 +82,20 @@ func (fs *FilterSystem) Stop() {
fs.sub.Unsubscribe()
}
-// Add adds a filter to the filter manager
-func (fs *FilterSystem) Add(filter *Filter, filterType FilterType) (int, error) {
+// Acquire filter system maps lock, required to force lock acquisition
+// sequence with filterMu acquired first to avoid deadlocks by callbacks
+func (fs *FilterSystem) Lock() {
fs.filterMu.Lock()
- defer fs.filterMu.Unlock()
+}
+
+// Release filter system maps lock
+func (fs *FilterSystem) Unlock() {
+ fs.filterMu.Unlock()
+}
+// Add adds a filter to the filter manager
+// Expects filterMu to be locked.
+func (fs *FilterSystem) Add(filter *Filter, filterType FilterType) (int, error) {
id := fs.filterId
filter.created = time.Now()
@@ -110,10 +119,8 @@ func (fs *FilterSystem) Add(filter *Filter, filterType FilterType) (int, error)
}
// Remove removes a filter by filter id
+// Expects filterMu to be locked.
func (fs *FilterSystem) Remove(id int) {
- fs.filterMu.Lock()
- defer fs.filterMu.Unlock()
-
delete(fs.chainFilters, id)
delete(fs.pendingTxFilters, id)
delete(fs.logFilters, id)