فهرست منبع

Revert "fix potential deadlock of pub/sub module"

This reverts commit 3d3f9694a426eafc32640a643b5399a58209da1c.
j75689 4 سال پیش
والد
کامیت
6e960cc850
2فایلهای تغییر یافته به همراه6 افزوده شده و 14 حذف شده
  1. 6 3
      eth/filters/api.go
  2. 0 11
      eth/filters/filter_system.go

+ 6 - 3
eth/filters/api.go

@@ -117,16 +117,19 @@ func (api *PublicFilterAPI) NewPendingTransactionFilter() rpc.ID {
 		pendingTxs   = make(chan []common.Hash)
 		pendingTxSub = api.events.SubscribePendingTxs(pendingTxs)
 	)
-	f := &filter{typ: PendingTransactionsSubscription, deadline: time.NewTimer(api.timeout), hashes: make([]common.Hash, 0), s: pendingTxSub}
 	api.filtersMu.Lock()
-	api.filters[pendingTxSub.ID] = f
+	api.filters[pendingTxSub.ID] = &filter{typ: PendingTransactionsSubscription, deadline: time.NewTimer(api.timeout), hashes: make([]common.Hash, 0), s: pendingTxSub}
 	api.filtersMu.Unlock()
 
 	gopool.Submit(func() {
 		for {
 			select {
 			case ph := <-pendingTxs:
-				f.hashes = append(f.hashes, ph...)
+				api.filtersMu.Lock()
+				if f, found := api.filters[pendingTxSub.ID]; found {
+					f.hashes = append(f.hashes, ph...)
+				}
+				api.filtersMu.Unlock()
 			case <-pendingTxSub.Err():
 				api.filtersMu.Lock()
 				delete(api.filters, pendingTxSub.ID)

+ 0 - 11
eth/filters/filter_system.go

@@ -174,17 +174,6 @@ func (sub *Subscription) Unsubscribe() {
 		// this ensures that the manager won't use the event channel which
 		// will probably be closed by the client asap after this method returns.
 		<-sub.Err()
-
-	drainLoop:
-		for {
-			select {
-			case <-sub.f.logs:
-			case <-sub.f.hashes:
-			case <-sub.f.headers:
-			default:
-				break drainLoop
-			}
-		}
 	})
 }