Repository navigation
libstore: curl retry: reset content-encoding and don't use string after move - #12603
Conversation
Maybe the fake github in |
|
@roberth The problem is that I don't know exactly which replies Github sent. But here are instruction how to trigger the bug:
from http.server import BaseHTTPRequestHandler, HTTPServer
def gzipencode(content):
from io import BytesIO
import gzip
out = BytesIO()
f = gzip.GzipFile(fileobj=out, mode='w', compresslevel=5)
f.write(content.encode())
f.close()
return out.getvalue()
strcontent = """{
x86_64-linux = "/nix/store/kwck2vdfdp2v4jr9c4daryyk9mlbx406-nix-2.24.12";
i686-linux = "/nix/store/s9qqyxzcgjl7xrfhnnjiiy9v876pcphi-nix-2.24.12";
aarch64-linux = "/nix/store/pmj4g05d4nlr3gcr8nyadgwir3svbkmx-nix-2.24.12";
riscv64-linux = "/nix/store/nzr3m4x3mcnfpnmyap31f9pviwv29vyc-nix-riscv64-unknown-linux-gnu-2.24.12";
x86_64-darwin = "/nix/store/pf6msb0yzccznd75yil32mzk284h90z4-nix-2.24.12";
aarch64-darwin = "/nix/store/vaaakw66qnbw4g007rf2nggy0rmhf8fh-nix-2.24.12";
}"""
strerror = "429: Too Many Requests"
content = gzipencode(strcontent)
error = gzipencode(strerror)
class TestHTTP429(BaseHTTPRequestHandler):
GZIP_ERROR = False
ctr = 0
def do_GET(self):
fail = TestHTTP429.ctr % 2 == 0
TestHTTP429.ctr = TestHTTP429.ctr + 1
self.protocol_version = 'HTTP/1.1'
if fail:
body = error if TestHTTP429.GZIP_ERROR else strerror.encode()
self.send_response(429)
else:
body = content
self.send_response(200)
self.send_header("Content-Type", "text/plain; charset=utf-8")
self.send_header("Accept-Ranges", "bytes")
self.send_header("Content-Length", str(len(body)))
if not fail or TestHTTP429.GZIP_ERROR:
self.send_header("Content-Encoding", "gzip")
self.end_headers()
self.wfile.write(body)
self.wfile.flush()
if __name__ == "__main__":
server = HTTPServer(("127.0.0.1", 10000), TestHTTP429)
server.serve_forever()
With If My patch does not fail this test. Maybe a test case should be added, i.e. with a fake HTTP server that sends two hard coded responses. Edit: Change error message to match #12419 and simplify code |
|
@SuperSandro2000 added backport label. |
…2603 libstore: curl retry: reset content-encoding and don't use string after move (backport #12603)
Motivation
While analyzing #12419 I discovered that in case of a HTTP error
429the retry behavior is problematic. The sameTransferItemis issued again.decompressionSinkis not reinitialized, so that it might be used afterfinish()is called. Furthermore it's possible thaterrorSinkis used again aftererrorSink->sis moved.Additionally the
Content-Encodingheader of the HTTP429response and of the HTTP200response might be different. In this case the decompression of the HTTP200response body might fail.Context
Might fix #12419, although I wasn't able to provoke any HTTP error
429on Github. Github seems to prefergzipencoding and the response body of the error response shown in the issue seems to be short, but not empty. Thus it seems to be unlikely that this error response contained the headerContent-Encoding: gzip, while the reply with the content probably had it set. More details about the responses would be helpful.Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.