-
Notifications
You must be signed in to change notification settings - Fork 19
Not returning on connection close for chainsync, block-fetch and tx-submission protocol #1141
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Jenita <[email protected]>
Signed-off-by: Jenita <[email protected]>
Signed-off-by: Jenita <[email protected]>
Closes #1112 |
protocol/blockfetch/client.go
Outdated
c.stateMutex.Lock() | ||
defer c.stateMutex.Unlock() | ||
c.currentState = newState | ||
} |
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.
The protocol.Protocol
base type already tracks the current state. It should be possible to add IsDone()
there in a generic way by checking that the current state matches the initial state and/or the current state having AgencyNone
.
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.
updated, could you please review when you get a chance ?
Signed-off-by: Jenita <[email protected]>
Signed-off-by: Jenita <[email protected]>
Signed-off-by: Jenita <[email protected]>
protocol/blockfetch/blockfetch.go
Outdated
return err | ||
} | ||
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.
These checks need to be done at the top level, in Connection
. We have an error handler for muxer errors there, and we can check the state of all active protocols from there.
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.
made the cahange, could you please review?
Signed-off-by: Jenita <[email protected]>
errStr := err.Error() | ||
return strings.Contains(errStr, "connection reset") || | ||
strings.Contains(errStr, "broken pipe") | ||
} |
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.
We should check for error types rather than substring matches of the Error()
output. Do we actually get any "connection closed" error that isn't io.EOF
?
connection.go
Outdated
// checkProtocols checks if the protocols are explicitly stopped by the client- treat as normal connection closure | ||
func (c *Connection) checkProtocols() bool { | ||
// Check chain-sync protocol | ||
if c.chainSync != nil && (!c.chainSync.Client.IsDone() || !c.chainSync.Server.IsDone()) { |
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.
.Client
or .Server
can be nil, so we need nil
checks against both
connection.go
Outdated
} | ||
|
||
// Check block-fetch protocol | ||
if c.blockFetch != nil && (!c.blockFetch.Client.IsDone() || !c.blockFetch.Server.IsDone()) { |
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.
.Client
or .Server
can be nil, so we need nil
checks against both
connection.go
Outdated
} | ||
|
||
// Check tx-submission protocol | ||
if c.txSubmission != nil && (!c.txSubmission.Client.IsDone() || !c.txSubmission.Server.IsDone()) { |
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.
.Client
or .Server
can be nil, so we need nil
checks against both
// Check tx-submission protocol | ||
if c.txSubmission != nil && (!c.txSubmission.Client.IsDone() || !c.txSubmission.Server.IsDone()) { | ||
return false | ||
} |
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.
Let's also add LocalStateQuery
, LocalTxMonitor
, and LocalTxSubmission
to this. It should be safe to do the NtN and NtC protocols all together with the nil
checks.
protocol/blockfetch/client.go
Outdated
case MessageTypeBatchDone: | ||
err = c.handleBatchDone() | ||
case MessageTypeClientDone: | ||
return nil |
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.
This doesn't belong here. The client will never receive the ClientDone
message, only the server.
protocol/chainsync/client.go
Outdated
case MessageTypeIntersectNotFound: | ||
err = c.handleIntersectNotFound(msg) | ||
case MessageTypeDone: | ||
return nil |
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.
This doesn't belong here. The client will never receive this message, only the server
currentState := p.CurrentState() | ||
if entry, exists := p.config.StateMap[currentState]; exists { | ||
return entry.Agency == AgencyNone | ||
} |
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.
This should also return true
if the current state is the same as the configured initial protocol state.
protocol/txsubmission/client.go
Outdated
case MessageTypeRequestTxs: | ||
err = c.handleRequestTxs(msg) | ||
case MessageTypeDone: | ||
return nil |
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.
This isn't needed. The client will never receive this message, only the server
stateRespChan: stateChan, | ||
} | ||
return <-stateChan | ||
} |
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.
There's probably a cleaner way to do this. Instead, let's make currentState
defined at the top of stateLoop()
a field in the Protocol
type, and then we can access it more directly.
Signed-off-by: Jenita <[email protected]>
Closes #1112