Skip to content

Commit 72e60de

Browse files
committed
Merge pull request bnb-chain#2563 from obscuren/rpcaddr-fix
eth: fixed double close of channel. Fixes bnb-chain#2555
2 parents a5ff487 + 7c1f747 commit 72e60de

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎event/event.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ func (mux *TypeMux) Subscribe(types ...interface{}) Subscription {
6666
mux.mutex.Lock()
6767
defer mux.mutex.Unlock()
6868
if mux.stopped {
69+
// set the status to closed so that calling Unsubscribe after this
70+
// call will short curuit
71+
sub.closed = true
6972
close(sub.postC)
7073
} else {
7174
if mux.subm == nil {

‎event/event_test.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ import (
2525

2626
type testEvent int
2727

28+
func TestSubCloseUnsub(t *testing.T) {
29+
// the point of this test is **not** to panic
30+
var mux TypeMux
31+
mux.Stop()
32+
sub := mux.Subscribe(int(0))
33+
sub.Unsubscribe()
34+
}
35+
2836
func TestSub(t *testing.T) {
2937
mux := new(TypeMux)
3038
defer mux.Stop()

0 commit comments

Comments
 (0)