Skip to content

Fix AttributeError in cluster metrics recording when connection is None or ClusterNode object instance is used to extract the connection info#3999

Merged
petyaslavova merged 2 commits intomasterfrom
ps_fix_some_metrics_extraction_with_cluster_errors
Mar 16, 2026
Merged

Fix AttributeError in cluster metrics recording when connection is None or ClusterNode object instance is used to extract the connection info#3999
petyaslavova merged 2 commits intomasterfrom
ps_fix_some_metrics_extraction_with_cluster_errors

Conversation

@petyaslavova
Copy link
Copy Markdown
Collaborator

@petyaslavova petyaslavova commented Mar 11, 2026

Fix AttributeError in cluster metrics recording when connection is None

When exceptions occur in RedisCluster before a connection is established
(e.g., AuthenticationError, MaxConnectionsError), the connection variable
is None or a ClusterNode object (which lacks a 'db' attribute). This caused
AttributeError when recording metrics.

Changes:

  • Use e.connection (which is set to target_node) instead of connection
    variable for metrics recording in exception handlers
  • Add defensive checks in _record_command_metric for missing attributes
  • ClusterNode objects now default to db="0" for metrics

Fixes #3997


Note

Medium Risk
Touches Redis Cluster command execution error paths and observability hooks; functional behavior should be unchanged but regressions could affect error handling/metrics accuracy during connection establishment failures.

Overview
Prevents AttributeError during Redis Cluster observability by consistently recording command duration metrics using e.connection (which may be a ClusterNode fallback) across exception handlers, including AuthenticationError, MaxConnectionsError, and connection/timeout-related failures.

Makes _record_command_metric defensive when connection is None or lacks db, defaulting host/port/db to safe values, and expands tests to cover sync and asyncio cluster scenarios for these error cases and successful metric recording with a non-default DB.

Written by Cursor Bugbot for commit bc9ddb4. This will update automatically on new commits. Configure here.

…ne or ClusterNode object instance is used to extract the connection info
@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented Mar 11, 2026

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@petyaslavova petyaslavova merged commit 18b5352 into master Mar 16, 2026
64 checks passed
@petyaslavova petyaslavova deleted the ps_fix_some_metrics_extraction_with_cluster_errors branch March 16, 2026 07:42
petyaslavova added a commit that referenced this pull request Mar 23, 2026
…ne or ClusterNode object instance is used to extract the connection info (#3999)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cluster error handling raises AttributeError: 'ClusterNode' object has no attribute 'db' after connection timeout

2 participants