Skip to content

Conversation

@jameslovespancakes
Copy link

Fixes #3081

During server shutdown, the _cleanup() function in runners.py calls close_if_idle() on all connection objects. However, if a connection was created but connection_task() hasn't called _setup_connection() yet, the _http attribute doesn't exist, causing an AttributeError.

The HttpProtocolMixin already provides an 'http' property (lines 73-77) that safely handles this case using hasattr(). This commit updates close_if_idle() to use the property instead of direct attribute access.

Changes:

  • Changed self._http to self.http in close_if_idle() method
  • This leverages the existing property that returns None when _http doesn't exist yet
  • Maintains exact same behavior for initialized connections
  • Prevents AttributeError for uninitialized connections during shutdown

Fixes sanic-org#3081

During server shutdown, the _cleanup() function in runners.py calls
close_if_idle() on all connection objects. However, if a connection
was created but connection_task() hasn't called _setup_connection()
yet, the _http attribute doesn't exist, causing an AttributeError.

The HttpProtocolMixin already provides an 'http' property (lines 73-77)
that safely handles this case using hasattr(). This commit updates
close_if_idle() to use the property instead of direct attribute access.

Changes:
- Changed self._http to self.http in close_if_idle() method
- This leverages the existing property that returns None when _http
  doesn't exist yet
- Maintains exact same behavior for initialized connections
- Prevents AttributeError for uninitialized connections during shutdown
@jameslovespancakes jameslovespancakes requested a review from a team as a code owner October 21, 2025 01:38
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.

Sanic is crashing while trying to find field self._http but it not exists

1 participant