http: close a connection after its response times out - #5133
Open
KernelClint wants to merge 1 commit into
Open
Conversation
AI-Assisted: yes (GPT-5.6-Cyber)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5133 +/- ##
=======================================
Coverage 80.63% 80.64%
=======================================
Files 390 390
Lines 96936 96938 +2
=======================================
+ Hits 78168 78176 +8
+ Misses 18768 18762 -6
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HTTP_Client.request()sends a request, waits for the response, and keeps the connection open so alater request to the same host and port can reuse it.
When the wait times out,
sr1()returns nothing andscapy/layers/http.py:938-948breaks out of the request loop without touching the socket. The connection stays in the reusable
pool with an unanswered request outstanding on it.
If the response then arrives late, it is sitting on the stream when the next request goes out.
Matching does not help: at
scapy/layers/http.py:591-592any HTTP response answers any HTTPrequest, so the stale one is returned as the new request's answer. A run that asked for
/secondreceived the body
first.The change discards the connection instead:
An HTTP/1.1 client has no way to tell whether a later response on that stream belongs to the
abandoned request, so reuse is not safe. Requests that get a timely response are unaffected — only
the timeout path changes.
The added regression drives a client whose first response never arrives and asserts the second
request opens a new connection and gets its own answer. Without the source change it fails.
Performance was measured on one computer, before and after the fix: a normal request took 32.5 µs
before and 31.7 µs after. Repeat runs moved by about 4%, so that difference is smaller than the
test can distinguish.