Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w3w61-001hQz-1L for pgsql-hackers@arkaria.postgresql.org; Sat, 21 Mar 2026 13:10:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w3w5z-00AOWt-1w for pgsql-hackers@arkaria.postgresql.org; Sat, 21 Mar 2026 13:10:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w3w5z-00AOWk-0b for pgsql-hackers@lists.postgresql.org; Sat, 21 Mar 2026 13:10:27 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w3w5x-00000000KGW-3Icg for pgsql-hackers@lists.postgresql.org; Sat, 21 Mar 2026 13:10:26 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-660a58841d4so1856906a12.0 for ; Sat, 21 Mar 2026 06:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774098623; cv=none; d=google.com; s=arc-20240605; b=j6pGo/fe1Kbpd3Ag3X19Q/XDl44bz/dqCI77uFzp3lQ4WsPiy8rykO7GuCcS6zUL+O JZPq2MST/Iwj+jzyteVGa9mc/qLUaNLlYBZAVYGqxQo+N32VVCNwO4OxrGlCuDNcMm3I iy8y2gOPW6yQauPfSl46BO9huAZSXao9R0gDpZS9QZdOo08roJ4WKu9byMKrypVtMmLz mPRYuzB5AymJHXxEHQYKiSeMHRpNfr7zF8PHzmadjuHk2ZpY+0itxR5dMAVHfQ5vJVYm GRJj4y5UGOXdqOpWimWP/KwuawBaGB65ro9A8R/CUPRDbdkoY1oyLbo4hgwSNkPeMAzw 6agA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=Sm/136jeWrpTyWX/z1fW6EhIP5cN81ObAxZHIdt104U=; fh=wb9NqnYQimSGVvxgRUtQskkilZUMkEI7NNKqWcZGqa4=; b=d+3hyaDVWpHYOJoQDkiHqJW4c3PXdWv6NJzUHLn92Dd4TfdI/RVkKM9iyjffGtsnaG WkTHZFG7OnNNuBThZjuyPdfu600WvImOeUPdtb+Z0J8Md9CGhm4JkFCocITmSK8qgXjF IfTFStoPJLlwSXRg9Nvl5ToszJ0yXHw272yyWh5YcYrJhuQVKt9WQUZzf/f6qLEUcL1T +ZqfZ2BgkWAfmOnpBVmKOZWBkhTbaBldZvTSoW3Y4uHSMj7BJB2zZhBzQdokGtRJ/qkz Fe3ii8ZYfi4DBRbs+QSLXTNfWevC3A/Zd1dhZJa8tCWPED6YK0S3OaYkBQrkUSZGiIHD hlvg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774098623; x=1774703423; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Sm/136jeWrpTyWX/z1fW6EhIP5cN81ObAxZHIdt104U=; b=ihOvFkpo2dt9Djm+uKv+QvnutUbRe35lEkxMpRbJhueWxGT7F09vF+OK6oXESX9Zba AJqK/NpdmgldAvnrp/XgWfmZe5mmO/u6PeMRM8qkYrtJU6gDBlZyfaRw1XaG7WwhCekX ElHFQ07IAcFh3rWVkFtAJOQr9EMFtdg3APZ/A2kQsJfKuEPKlSqvzadCIIb5/V6Zx0k0 jro8O7ck1HBxoRAcWARTTFcEri/rHMQKBp5QHGoAa8MvNs2DZrj+8znTEVEgTy+LB5GG Fvct7qnHj+f389lxFoRqs/1SgaqdcmUITtK3J7uMon43iM45X9kz68ZluF0tFpUC4OM9 lcJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774098623; x=1774703423; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Sm/136jeWrpTyWX/z1fW6EhIP5cN81ObAxZHIdt104U=; b=U24Nvb2JMU7UwV8XqGbUc5MaF13LgUMpLYRFpCCA6suyUjU1km4BWW4GkIxxTTYKtn LEd4hUTMxEJG271Y/5Kp8IZW77gd8FGug+0H8XNPZPfwsIKcpz6HReONrj8YspxwfJR3 DrxYdicayC1ZhPRpkzBdn/aubpWEXr8vh0GjKU6Tm2u86nfyKIV7nv6VzPjDRkOJjV4R 49Rc2+Zg4ZbgI1BR2XzSegcN+w7Qdt+Mk84YgOIjo0GyYnfp3xQJ4/6wpDR2Iz14zdqW VRMoJq+9r8LYP9vI6PUCJAQuKdlzna3rTaG6CWI2f4l+k46qfpMOn7TTLAj3VekC9u4w EMZw== X-Gm-Message-State: AOJu0Yww5RtksgW0JupEGF+66t3H0pB371j3hVYF+CUFtJR2O5Lh8aSZ 8JUaHF+tCt1Qq++9/426uEECs9pUmMA+bR9ay29j0xR+M+fbMfmshqvP9ysJickc/fqVaHZjisQ SeYepLc4tayMQ8akpS9s8WjfwLNlL3ZUuEd5E4+7aFw== X-Gm-Gg: ATEYQzzevi+GlRS+g9XeurTvXtg5aR0tPjfjJ7ft6v8gPc+L2KQPbViLA7Z1h+Gu04i EGNC3R9gKnNQPJIyU7MIpHVf6WOM09lglu4NW7rs38iMesmpHa2Enl2ztnezztlMYgLz2i+OVM6 7dhqZQFsuSvU7Fmr0Qms2EoiKNq7CDVL9RyaCvLja7UhP/U6sbMqsQisp8bQQ6yaqtwbHzO4aXz 5+ExGC8CVMQXiE/XLyFQX4xR1Werku4Cf4livGaQsJK5940jvT0WOwZLeSKRy3qxmRgvWtBNEPc 5hFz8gPti1igkCjvwlYmC2sVw+mGSXiDdSdrOQ/43TPkURwWT6mr4nRPIfQP9BDxkwMlzrE9 X-Received: by 2002:a17:906:a856:b0:b98:12d5:9fa6 with SMTP id a640c23a62f3a-b982f362dadmr334333466b.33.1774098623034; Sat, 21 Mar 2026 06:10:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jianghua Yang Date: Sat, 21 Mar 2026 06:09:46 -0700 X-Gm-Features: AaiRm53RmI57K33jU9no8VmEcggskK7AUK6iKpYQ61P7pFhdIPMkrPCH4yx7ggY Message-ID: Subject: Re: basebackup: add missing deflateEnd() in gzip compression sink To: Michael Paquier Cc: pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000038f9dd064d8886f9" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000038f9dd064d8886f9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for reviewing, Michael. > based on the argument of the permanent connection my take is that > this cleanup warrants a backpatch. Agreed. The current code leaks zlib internal state on every archive, and on a long-lived replication connection those allocations just pile up with no cleanup until the connection ends. Michael Paquier =E4=BA=8E2026=E5=B9=B43=E6=9C=8820=E6= =97=A5=E5=91=A8=E4=BA=94 23:09=E5=86=99=E9=81=93=EF=BC=9A > On Fri, Mar 20, 2026 at 10:02:44AM -0700, Jianghua Yang wrote: > > While reviewing the backup compression backends, I noticed that the gzi= p > > sink (basebackup_gzip.c) never calls deflateEnd(), unlike the lz4 and > > zstd sinks which properly free their compression contexts. > > > > This means each archive (one per tablespace) leaks ~256KB of zlib > > internal state until the backup's memory context is destroyed. On the > > ERROR path, the zlib context is not released at all since there is no > > gzip-specific cleanup callback. > > Yes, you are right on this one. This code could be better in cleaning > up the resources it is working on (and note that all the other > gzip-related code paths call the end() part if doing an init() or an > init2()). Leaking that once per archive may not look like a big deal, > but this is backend-side code we are talking about, and on a > persistent replication connection it is not really cool to lose the > context of this data with garbage coming from zlib piling up, so based > on the argument of the permanent connection my take is that this > cleanup warrants a backpatch. > -- > Michael > --00000000000038f9dd064d8886f9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
=C2=A0 Thanks for reviewing, Michael.

=C2=A0 > b= ased on the argument of the permanent connection my take is that
=C2=A0 = > this cleanup warrants a backpatch.

=C2=A0 Agreed. The current c= ode leaks zlib internal state on every archive,
=C2=A0 and on a long-liv= ed replication connection those allocations just
=C2=A0 pile up with no = cleanup until the connection ends.

Michael Paquier <= ;michael@paquier.xyz> =E4=BA= =8E2026=E5=B9=B43=E6=9C=8820=E6=97=A5=E5=91=A8=E4=BA=94 23:09=E5=86=99=E9= =81=93=EF=BC=9A
= On Fri, Mar 20, 2026 at 10:02:44AM -0700, Jianghua Yang wrote:
> While reviewing the backup compression backends, I noticed that the gz= ip
> sink (basebackup_gzip.c) never calls deflateEnd(), unlike the lz4 and<= br> > zstd sinks which properly free their compression contexts.
>
> This means each archive (one per tablespace) leaks ~256KB of zlib
> internal state until the backup's memory context is destroyed. On = the
> ERROR path, the zlib context is not released at all since there is no<= br> > gzip-specific cleanup callback.

Yes, you are right on this one.=C2=A0 This code could be better in cleaning=
up the resources it is working on (and note that all the other
gzip-related code paths call the end() part if doing an init() or an
init2()).=C2=A0 Leaking that once per archive may not look like a big deal,=
but this is backend-side code we are talking about, and on a
persistent replication connection it is not really cool to lose the
context of this data with garbage coming from zlib piling up, so based
on the argument of the permanent connection my take is that this
cleanup warrants a backpatch.
--
Michael
--00000000000038f9dd064d8886f9--