-
Notifications
You must be signed in to change notification settings - Fork 216
Closed as not planned
Labels
proposalA proposal for an a new API or behavior. See CONTRIBUTING.md.A proposal for an a new API or behavior. See CONTRIBUTING.md.proposal-declinedProposals that have been declined.Proposals that have been declined.
Description
Transport interface currently only supports Connect method.
This is sufficient for most cases, however it does not give granular control over transports lifecycle. This specifically impacts incase I want to implement my custom transport, like server example.
Describe the solution you'd like
introduce Close() error
in Transport interface
type Transport interface {
Connect(ctx context.Context) (Connection, error)
// Close closes the transport, releasing any resources.
//
Close() error
}
This will give idiomatic way to close a transport object. Following resource clearance logic can be implemented.
// StreamableServerTransport explicitly close connections
func (t *StreamableServerTransport) Close() error {
if t.connection != nil {
t.connection.Close()
t.connection = nil
}
return nil
}
// SSEServerTransport mark transport closed
func (t *SSEServerTransport) Close() error {
t.mu.Lock()
defer t.mu.Unlock()
if !t.closed {
t.closed = true
close(t.done)
}
return nil
}
// InMemoryTransport explicitly close io.ReadWriteCloser
func (t *InMemoryTransport) Close() error { return t.rwc.Close() }
// LoggingTransport close internal Transport instance
func (t *LoggingTransport) Close() error { return t.Transport.Close() }
// StdioTransport empty implementation
func (*StdioTransport) Close() error { return nil }
// CommandTransport empty implementation
func (t *CommandTransport) Close() error { return nil }
This change can also help write clean implementation for #440
Metadata
Metadata
Assignees
Labels
proposalA proposal for an a new API or behavior. See CONTRIBUTING.md.A proposal for an a new API or behavior. See CONTRIBUTING.md.proposal-declinedProposals that have been declined.Proposals that have been declined.