Compare commits

2 Commits

2 changed files with 9 additions and 6 deletions

View File

@@ -62,13 +62,11 @@ func sanitizeAddress(addr string) string {
func validateAddressFormat(addr string) error {
host, _, err := net.SplitHostPort(addr)
if err != nil {
// If SplitHostPort fails, it means addr is not in host:port format
host = addr
}
if host != "" {
if err == nil {
// Successfully split host:port, use just the host part
addr = host
}
if len(addr) > MaxAddressLength || len(addr) < MinAddressLength {
return fmt.Errorf("invalid address length: got %d, want between %d and %d",
len(addr), MinAddressLength, MaxAddressLength)

View File

@@ -61,7 +61,12 @@ func (c *samClient) generateDestination(ctx context.Context, keyType string) (*I
if err != nil {
return nil, fmt.Errorf("connecting to SAM bridge: %w", err)
}
defer conn.Close()
// Ensure connection is always closed, even on error paths
defer func() {
if closeErr := conn.Close(); closeErr != nil {
log.WithError(closeErr).Debug("Error closing SAM connection")
}
}()
if err := c.handshake(ctx, conn); err != nil {
return nil, fmt.Errorf("SAM handshake failed: %w", err)