Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion httpcore/_async/http11.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ def is_available(self) -> bool:

def has_expired(self) -> bool:
now = time.monotonic()
keepalive_expired = self._expire_at is not None and now > self._expire_at
# Read `_expire_at` once into a local: another thread may reset it to
# `None` (see `handle_async_request`) between the `is not None` check and
# the comparison, which raises a `TypeError` on the free-threaded build
# where there is no GIL to serialise the two attribute reads.
expire_at = self._expire_at
keepalive_expired = expire_at is not None and now > expire_at

# If the HTTP connection is idle but the socket is readable, then the
# only valid state is that the socket is about to return b"", indicating
Expand Down
7 changes: 6 additions & 1 deletion httpcore/_async/http2.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,12 @@ def is_available(self) -> bool:

def has_expired(self) -> bool:
now = time.monotonic()
return self._expire_at is not None and now > self._expire_at
# Read `_expire_at` once into a local: another thread may reset it to
# `None` (see `handle_async_request`) between the `is not None` check and
# the comparison, which raises a `TypeError` on the free-threaded build
# where there is no GIL to serialise the two attribute reads.
expire_at = self._expire_at
return expire_at is not None and now > expire_at

def is_idle(self) -> bool:
return self._state == HTTPConnectionState.IDLE
Expand Down
7 changes: 6 additions & 1 deletion httpcore/_sync/http11.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ def is_available(self) -> bool:

def has_expired(self) -> bool:
now = time.monotonic()
keepalive_expired = self._expire_at is not None and now > self._expire_at
# Read `_expire_at` once into a local: another thread may reset it to
# `None` (see `handle_request`) between the `is not None` check and
# the comparison, which raises a `TypeError` on the free-threaded build
# where there is no GIL to serialise the two attribute reads.
expire_at = self._expire_at
keepalive_expired = expire_at is not None and now > expire_at

# If the HTTP connection is idle but the socket is readable, then the
# only valid state is that the socket is about to return b"", indicating
Expand Down
7 changes: 6 additions & 1 deletion httpcore/_sync/http2.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,12 @@ def is_available(self) -> bool:

def has_expired(self) -> bool:
now = time.monotonic()
return self._expire_at is not None and now > self._expire_at
# Read `_expire_at` once into a local: another thread may reset it to
# `None` (see `handle_request`) between the `is not None` check and
# the comparison, which raises a `TypeError` on the free-threaded build
# where there is no GIL to serialise the two attribute reads.
expire_at = self._expire_at
return expire_at is not None and now > expire_at

def is_idle(self) -> bool:
return self._state == HTTPConnectionState.IDLE
Expand Down
Loading