-
Notifications
You must be signed in to change notification settings - Fork 131
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
Add SDK Router message handling #316
Changes from 1 commit
91c34d2
4baa94d
b6aac63
78420bf
28ad9f8
b10e5dc
96b7b09
5154ca3
1b32de6
f5d8a0d
09126b4
d2e6c19
215e315
c3287fe
3328e14
65935bd
72f7ab1
e06646e
6ad4f35
d332ad7
60de385
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 |
---|---|---|
|
@@ -365,15 +365,16 @@ func (n *network) AppRequest(ctx context.Context, nodeID ids.NodeID, requestID u | |
// If the response handler returns an error it is propagated as a fatal error. | ||
func (n *network) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error { | ||
n.lock.Lock() | ||
defer n.lock.Unlock() | ||
|
||
if n.closed.Get() { | ||
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 is a very subtle change. So we should be terrified to make it. I believe we must hold the lock when checking 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. As discussed offline I'll see if I can make a separate regression test for this invariant as a follow-up to this PR. 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 documented the invariant on |
||
n.lock.Unlock() | ||
return nil | ||
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. Are we okay with dropping responses (and timeouts) that should have been sent to the SDK router after we close the network? 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. If we are not okay with this - then I think we'll need to be fairly careful around what gets passed through to the router. 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. We chatted offline but agreed it was cleanest to leave the |
||
} | ||
|
||
log.Debug("received AppResponse from peer", "nodeID", nodeID, "requestID", requestID) | ||
|
||
handler, exists := n.markRequestFulfilled(requestID) | ||
n.lock.Unlock() | ||
if !exists { | ||
log.Debug("forwarding AppResponse to SDK router", "nodeID", nodeID, "requestID", requestID, "responseLen", len(response)) | ||
return n.router.AppResponse(ctx, nodeID, requestID, response) | ||
|
@@ -393,15 +394,16 @@ func (n *network) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID | |
// returns error only when the response handler returns an error | ||
func (n *network) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32) error { | ||
n.lock.Lock() | ||
defer n.lock.Unlock() | ||
|
||
if n.closed.Get() { | ||
n.lock.Unlock() | ||
return nil | ||
} | ||
|
||
log.Debug("received AppRequestFailed from peer", "nodeID", nodeID, "requestID", requestID) | ||
|
||
handler, exists := n.markRequestFulfilled(requestID) | ||
n.lock.Unlock() | ||
if !exists { | ||
log.Debug("forwarding AppRequestFailed to SDK router", "nodeID", nodeID, "requestID", requestID) | ||
return n.router.AppRequestFailed(ctx, nodeID, requestID) | ||
|
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.
since
closed
is atomic, could we move this lock to directly beforehandler, exists := n.markRequestFulfilled(requestID)
?Should we move it to inside
markRequestFulfilled
instead?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.
Yeah that makes much more sense than what I was currently doing.