fix concurrent map write (#1882)

This commit is contained in:
Alex Sharov 2021-05-05 10:16:57 +07:00 committed by GitHub
parent 7c60ec3ec0
commit 61c20798db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,8 +56,8 @@ func (e *Events) AddPendingTxsSubscription(s PendingTxsSubscription) {
} }
func (e *Events) OnNewHeader(newHeader *types.Header) { func (e *Events) OnNewHeader(newHeader *types.Header) {
e.lock.RLock() e.lock.Lock()
defer e.lock.RUnlock() defer e.lock.Unlock()
for i, sub := range e.headerSubscriptions { for i, sub := range e.headerSubscriptions {
if err := sub(newHeader); err != nil { if err := sub(newHeader); err != nil {
delete(e.headerSubscriptions, i) delete(e.headerSubscriptions, i)
@ -66,8 +66,8 @@ func (e *Events) OnNewHeader(newHeader *types.Header) {
} }
func (e *Events) OnNewPendingLogs(logs types.Logs) { func (e *Events) OnNewPendingLogs(logs types.Logs) {
e.lock.RLock() e.lock.Lock()
defer e.lock.RUnlock() defer e.lock.Unlock()
for i, sub := range e.pendingLogsSubscriptions { for i, sub := range e.pendingLogsSubscriptions {
if err := sub(logs); err != nil { if err := sub(logs); err != nil {
delete(e.pendingLogsSubscriptions, i) delete(e.pendingLogsSubscriptions, i)
@ -76,8 +76,8 @@ func (e *Events) OnNewPendingLogs(logs types.Logs) {
} }
func (e *Events) OnNewPendingBlock(block *types.Block) { func (e *Events) OnNewPendingBlock(block *types.Block) {
e.lock.RLock() e.lock.Lock()
defer e.lock.RUnlock() defer e.lock.Unlock()
for i, sub := range e.pendingBlockSubscriptions { for i, sub := range e.pendingBlockSubscriptions {
if err := sub(block); err != nil { if err := sub(block); err != nil {
delete(e.pendingBlockSubscriptions, i) delete(e.pendingBlockSubscriptions, i)
@ -86,8 +86,8 @@ func (e *Events) OnNewPendingBlock(block *types.Block) {
} }
func (e *Events) OnNewPendingTxs(txs []types.Transaction) { func (e *Events) OnNewPendingTxs(txs []types.Transaction) {
e.lock.RLock() e.lock.Lock()
defer e.lock.RUnlock() defer e.lock.Unlock()
for i, sub := range e.pendingTxsSubscriptions { for i, sub := range e.pendingTxsSubscriptions {
if err := sub(txs); err != nil { if err := sub(txs); err != nil {
delete(e.pendingTxsSubscriptions, i) delete(e.pendingTxsSubscriptions, i)