Skip to content

Conversation

jkawan
Copy link
Contributor

@jkawan jkawan commented Aug 17, 2025

  1. Added changes to not return error while closing the connection for chainsync, block-fetch and tx-submission protocol- made changes in client,server and respective protocol files.
  2. Added unit tests to test the change.

Closes #1112

@jkawan jkawan requested a review from a team as a code owner August 17, 2025 01:43
@jkawan
Copy link
Contributor Author

jkawan commented Aug 17, 2025

  1. Added changes to not return error while closing the connection for chainsync, block-fetch and tx-submission protocol- made changes in client,server and respective protocol files.
  2. Added unit tests to test the change.

Closes #1112

c.stateMutex.Lock()
defer c.stateMutex.Unlock()
c.currentState = newState
}
Copy link
Contributor

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.

Copy link
Contributor Author

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 ?

return err
}
return err
}
Copy link
Contributor

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.

Copy link
Contributor Author

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?

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()) {
Copy link
Contributor

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()) {
Copy link
Contributor

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()) {
Copy link
Contributor

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

case MessageTypeBatchDone:
err = c.handleBatchDone()
case MessageTypeClientDone:
return nil
Copy link
Contributor

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.

case MessageTypeIntersectNotFound:
err = c.handleIntersectNotFound(msg)
case MessageTypeDone:
return nil
Copy link
Contributor

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

case MessageTypeRequestTxs:
err = c.handleRequestTxs(msg)
case MessageTypeDone:
return nil
Copy link
Contributor

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

@wolf31o2 wolf31o2 requested a review from agaffney September 20, 2025 14:02
// Stop the protocol explicitly
if err := chainSyncProtocol.Client.Stop(); err != nil {
t.Fatalf("failed to stop chain sync: %s", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really a good way to test this. The protocols aren't meant to be arbitrarily started/stopped from the outside, only from within the actual protocol. Instead, you should use the mock connection to send the Done message to shut it down.

}

return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that any of this is necessary. The docs for io.ReadFull() and binary.Read() both say that they'll only return io.EOF or io.ErrUnexpectedEOF. We may want to add a check for io.ErrUnexpectedEOF and remap it to io.EOF in the muxer (links below), and then we only need to check for errors.Is(err, io.EOF) anywhere below.

gouroboros/muxer/muxer.go

Lines 304 to 306 in a57c097

if errors.Is(err, io.ErrClosedPipe) {
err = io.EOF
}

gouroboros/muxer/muxer.go

Lines 331 to 333 in a57c097

if errors.Is(err, io.ErrClosedPipe) {
err = io.EOF
}

}

return true
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking further about this, we only need to care about the .Server side of each protocol. If we're acting as a client and the connection is unexpectedly closed (we didn't call .Close() ourselves), it should be an error condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't return an error on connection close when all protocols are shut down
2 participants