-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: confirm block import notifier is closed properly #1736
Changes from 6 commits
0a59cb3
a8cffd8
30338f7
6ed9d63
0bc1f97
2ae9572
0f95d68
2b16fa6
7f10eec
5f1c2a6
2b512b2
e3bd220
fd6d7cc
125b68a
ee0fc7b
6ca1a8b
d3eaa06
41bb429
f0f76f1
0164305
b7f658f
74f094d
8a49ae7
35180df
faf2664
db397cd
4b7d341
d5d0d57
f72e744
a478d5c
d5754d9
8b8066c
1acfba7
ce706cc
515391d
8ad895c
6b46fcd
6bfb77d
48f6db0
8b30110
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,12 +123,25 @@ type BlockListener struct { | |
cancelTimeout time.Duration | ||
} | ||
|
||
// NewBlockListener constructor for creating BlockListener | ||
func NewBlockListener(conn *WSConn) *BlockListener { | ||
bl := &BlockListener{ | ||
Channel: make(chan *types.Block, DEFAULT_BUFFER_SIZE), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be renamed |
||
wsconn: conn, | ||
cancel: make(chan struct{}, 1), | ||
cancelTimeout: defaultCancelTimeout, | ||
done: make(chan struct{}, 1), | ||
} | ||
return bl | ||
} | ||
|
||
// Listen implementation of Listen interface to listen for importedChan changes | ||
func (l *BlockListener) Listen() { | ||
go func() { | ||
defer func() { | ||
l.wsconn.BlockAPI.UnregisterImportedChannel(l.ChanID) | ||
close(l.done) | ||
close(l.Channel) | ||
}() | ||
|
||
for { | ||
|
@@ -180,6 +193,7 @@ func (l *BlockFinalizedListener) Listen() { | |
defer func() { | ||
l.wsconn.BlockAPI.UnregisterFinalisedChannel(l.chanID) | ||
close(l.done) | ||
close(l.channel) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the @arijitAD comment on PR #1769 (https://github.com/ChainSafe/gossamer/pull/1769/files#r696558481), I think that would be nice if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this probably shouldn't be closed here? it's a reader of the channel, not the writer, so should remove this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or this should be calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @edwardmack re-checking on this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @noot yes, I removed |
||
}() | ||
|
||
for { | ||
|
@@ -228,6 +242,20 @@ type ExtrinsicSubmitListener struct { | |
cancelTimeout time.Duration | ||
} | ||
|
||
// NewExtrinsicSubmitListener constructor to build new ExtrinsicSubmitListener | ||
func NewExtrinsicSubmitListener(conn *WSConn, extBytes []byte) *ExtrinsicSubmitListener { | ||
esl := &ExtrinsicSubmitListener{ | ||
importedChan: make(chan *types.Block, DEFAULT_BUFFER_SIZE), | ||
wsconn: conn, | ||
extrinsic: types.Extrinsic(extBytes), | ||
finalisedChan: make(chan *types.FinalisationInfo), | ||
cancel: make(chan struct{}, 1), | ||
done: make(chan struct{}, 1), | ||
cancelTimeout: defaultCancelTimeout, | ||
} | ||
return esl | ||
} | ||
|
||
// Listen implementation of Listen interface to listen for importedChan changes | ||
func (l *ExtrinsicSubmitListener) Listen() { | ||
// listen for imported blocks with extrinsic | ||
|
@@ -236,6 +264,8 @@ func (l *ExtrinsicSubmitListener) Listen() { | |
l.wsconn.BlockAPI.UnregisterImportedChannel(l.importedChanID) | ||
l.wsconn.BlockAPI.UnregisterFinalisedChannel(l.finalisedChanID) | ||
close(l.done) | ||
close(l.importedChan) | ||
close(l.finalisedChan) | ||
}() | ||
|
||
for { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,13 +213,9 @@ func (c *WSConn) initStorageChangeListener(reqID float64, params interface{}) (L | |
} | ||
|
||
func (c *WSConn) initBlockListener(reqID float64, _ interface{}) (Listener, error) { | ||
bl := &BlockListener{ | ||
Channel: make(chan *types.Block, DEFAULT_BUFFER_SIZE), | ||
wsconn: c, | ||
cancel: make(chan struct{}, 1), | ||
cancelTimeout: defaultCancelTimeout, | ||
done: make(chan struct{}, 1), | ||
} | ||
// TODO (ed) here the imported Channel get unregistered and closed in http.Stop | ||
// there doesn't seem to be an un-subscribe for this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this code to a constructor for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems there is logic to close imported channel in dot/http.go line 194-5, which in inside HTTPServer.Stop. There is also within Listener.Stop a call to cancelWithTimeout that gets called when unsubscribe is called. Should we move the imported channel close into Listener.Stop, then call listener.Stop from within HTTPServer.Stop? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea we should localise closing channels (managing internal state) to receiver functions of the struct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timwu20 the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But, the implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added imported channel close to defer in Listen methods. |
||
bl := NewBlockListener(c) | ||
|
||
if c.BlockAPI == nil { | ||
c.safeSendError(reqID, nil, "error BlockAPI not set") | ||
|
@@ -285,16 +281,9 @@ func (c *WSConn) initExtrinsicWatch(reqID float64, params interface{}) (Listener | |
return nil, err | ||
} | ||
|
||
// TODO (ed) the importedChan get deleted by unregister imported channel in defer in Listen (listeners.go line 236) | ||
// listen for built blocks | ||
esl := &ExtrinsicSubmitListener{ | ||
importedChan: make(chan *types.Block, DEFAULT_BUFFER_SIZE), | ||
wsconn: c, | ||
extrinsic: types.Extrinsic(extBytes), | ||
finalisedChan: make(chan *types.FinalisationInfo), | ||
cancel: make(chan struct{}, 1), | ||
done: make(chan struct{}, 1), | ||
cancelTimeout: defaultCancelTimeout, | ||
} | ||
esl := NewExtrinsicSubmitListener(c, extBytes) | ||
|
||
if c.BlockAPI == nil { | ||
return nil, fmt.Errorf("error BlockAPI not set") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -377,6 +377,7 @@ func (s *Service) initiate() error { | |
|
||
func (s *Service) waitForFirstBlock() error { | ||
ch := make(chan *types.Block) | ||
// TODO (ed) import channel is unregistered by defer, doesn't seem to be closed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this function has a problem. you can update the defer func to first |
||
id, err := s.blockState.RegisterImportedChannel(ch) | ||
if err != nil { | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this still a TODO?