Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130379 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 61D071A00BC for ; Tue, 17 Mar 2026 00:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1773706466; bh=i8qT7GepV1uUWb7xk5JZ92j+ROtktWOYkOEaKMGoBbA=; h=Date:Subject:To:References:From:In-Reply-To:From; b=aq8gSky4u82ueMOcUiRNrxEfVED4xUkA5f1ssXbkjAVoSydpSRwCN7wQOnr8YhrIN m1BCIbvrLKoZpFEgFAIPaTwitz6zEElp3BgD44Nls5xdZ6HvoRMB/hgBxiWatZhKUt ud8g0bM9IIQxDHndiqzWOFNcMW1/s7dRnnmaAgXYpJWpp0+Rwq1NQnMmMXXHKJq8PO JQGfwKG90ETB9rzOU8avP4P4hxvo0s6L2LYsTvOpZfEgxsCjbYZ7GvdStnRLx0p7y8 GDjK/vOhp0JyWVQf7k+jArjSGHaF16iMt2ieli7AyC4xxOyZDktxcmZkuR5DFLpp6M MNaXoIt2cetFA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A3EB0180059 for ; Tue, 17 Mar 2026 00:14:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail.fluentit.au (mail.fluentit.au [103.249.239.231]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 17 Mar 2026 00:14:22 +0000 (UTC) Received: from [IPV6:2402:1b40:8001:10:ad83:4a1a:55a:3f78] (unknown [IPv6:2402:1b40:8001:10:ad83:4a1a:55a:3f78]) (Authenticated sender: swilton@fluentit.au) by mail.fluentit.au (Postfix) with ESMTPSA id B10C0CF814 for ; Tue, 17 Mar 2026 08:14:13 +0800 (AWST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fluentit.au; s=default; t=1773706454; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yfA/YpREWg2Q8yy6yb/o7j8fBoepiOaAzvN951pNFKQ=; b=WKAarap3+k0NeBXRX2siaUb+qdfsezIMED5VO3xQVfq2XS6XC58KY7dRDn4ai+1VMPQvzj 79zctpAgph5r1BhsfdgA+CyYHxfb31hTZ+Ag9pJ7C+rWt1MqjB4gGShdvzfuaea/x90+mi RZujtUHf3vBCnzeOvl5L6Yfw8KNfXtg= Authentication-Results: ORIGINATING; auth=pass smtp.auth=swilton@fluentit.au smtp.mailfrom=swilton@fluentit.au Content-Type: multipart/alternative; boundary="------------yGSIK1CwwdKdEx0hka75PUAm" Message-ID: Date: Tue, 17 Mar 2026 08:14:13 +0800 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] SNMP MIB reset function To: internals@lists.php.net References: <5a2-69b78f00-11-50bc7700@253019388> <1c9534ff-d8c6-4939-a6f2-85a4c547ac0b@bastelstu.be> Content-Language: en-US In-Reply-To: <1c9534ff-d8c6-4939-a6f2-85a4c547ac0b@bastelstu.be> From: swilton@fluentit.au (Steven Wilton) This is a multi-part message in MIME format. --------------yGSIK1CwwdKdEx0hka75PUAm Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 17/03/2026 4:26 am, Tim Düsterhus wrote: > Hi > > On 3/16/26 06:03, swilton@fluentit.au wrote: >> I believe that the process is to send a message to the list, and >> gauge whether there is positive feedback before creating the RFC for >> voting.  Please let me know if I should create the RFC first? >> The PR is here: https://github.com/php/php-src/pull/21452/changes > > I suspect that SNMP is such a specialized and rarely used extension > that folks will be unable to meaningfully discuss an RFC for this > feature - at least not without you doing quite a bit of explaining. > This might be case where it's best to just find an informal agreement > with you providing a well-tested and well-explained patch rather than > doing a full RFC. I'm very happy to avoid the RFC process, and happy to explain/discuss the changes :) > > ---------- > > That said, I did some research, finding this man page: > https://linux.die.net/man/3/shutdown_mib. > > I'm seeing that the manpage states for init_mib(): >> It should be called before any other routine that manipulates or >> accesses the MIB tree. > > I'm seing that init_mib() is not currently called at all in ext/snmp. > Is the initialization implicitly happening as part of init_snmp()? > > For shutdown_mib() I'm seeing: > >> It is strongly recommended that one does not invoke shutdown_mib >> while there are SNMP sessions being actively managed. > > Will calling your proposed `snmp_init_mib()` function cause issues > when an existing SNMP object is being used after the call to > `snmp_init_mib()`? > I have interpreted the "actively managed" sessions as ones with requests in process (i.e. requests have been sent and we are using some form of select() to wait for the reply).  The other possibility is that calling mib_shutdown() would cause issues if a request is sent before iinit_mib() is called. I have written a test program that keeps a session across a mib_shutdown()/mib_init() with a query running on both sides, and it worked as expected with no memory access issues. > ---------- > > In your email you mention: > >> Another consideration is that the MIB tree persists across FPM >> requests because the MIB tree is kept as a global structure within >> SNMP library memory. > > Would calling `shutdown_mib()` in RSHUTDOWN (i.e. the end-of-request > handler) solve the problem of the MIB persisting across requests or is > it sometimes desirable that the MIB is persisted? > This is precisely why I mentioned the persistence of the MIB tree.  There is no reason to keep the tree between requests, so doing a shutdown_mib() followed by an init_mib() between requests would be a good idea, with the following caveats: * init_mib() depends on some environment variables.  I assume the environment is reset between requests, and if so init_mib() would need to be called between requests * init_mib() does read a bunch of files to parse the MIB tree, so it would be inefficient to call it between requests if no changes have been made to the MIB tree * I have just had a PR accepted in net-snmp to address a memory leak in the library when init_mib() is called multiple times, so it would cause a memory leak between requests until systems have been updated with this new patch > Best regards > Tim Düsterhus --------------yGSIK1CwwdKdEx0hka75PUAm Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 17/03/2026 4:26 am, Tim Düsterhus wrote:
Hi

On 3/16/26 06:03, swilton@fluentit.au wrote:
I believe that the process is to send a message to the list, and gauge whether there is positive feedback before creating the RFC for voting.  Please let me know if I should create the RFC first?
The PR is here: https://github.com/php/php-src/pull/21452/changes

I suspect that SNMP is such a specialized and rarely used extension that folks will be unable to meaningfully discuss an RFC for this feature - at least not without you doing quite a bit of explaining. This might be case where it's best to just find an informal agreement with you providing a well-tested and well-explained patch rather than doing a full RFC. 

I'm very happy to avoid the RFC process, and happy to explain/discuss the changes :)


----------

That said, I did some research, finding this man page: https://linux.die.net/man/3/shutdown_mib.

I'm seeing that the manpage states for init_mib():
It should be called before any other routine that manipulates or accesses the MIB tree.

I'm seing that init_mib() is not currently called at all in ext/snmp. Is the initialization implicitly happening as part of init_snmp()?

For shutdown_mib() I'm seeing:

It is strongly recommended that one does not invoke shutdown_mib while there are SNMP sessions being actively managed.

Will calling your proposed `snmp_init_mib()` function cause issues when an existing SNMP object is being used after the call to `snmp_init_mib()`? 

I have interpreted the "actively managed" sessions as ones with requests in process (i.e. requests have been sent and we are using some form of select() to wait for the reply).  The other possibility is that calling mib_shutdown() would cause issues if a request is sent before iinit_mib() is called.  

I have written a test program that keeps a session across a mib_shutdown()/mib_init() with a query running on both sides, and it worked as expected with no memory access issues.  

----------

In your email you mention:

Another consideration is that the MIB tree persists across FPM requests because the MIB tree is kept as a global structure within SNMP library memory.

Would calling `shutdown_mib()` in RSHUTDOWN (i.e. the end-of-request handler) solve the problem of the MIB persisting across requests or is it sometimes desirable that the MIB is persisted? 

This is precisely why I mentioned the persistence of the MIB tree.  There is no reason to keep the tree between requests, so doing a shutdown_mib() followed by an init_mib() between requests would be a good idea, with the following caveats:

  • init_mib() depends on some environment variables.  I assume the environment is reset between requests, and if so init_mib() would need to be called between requests
  • init_mib() does read a bunch of files to parse the MIB tree, so it would be inefficient to call it between requests if no changes have been made to the MIB tree
  • I have just had a PR accepted in net-snmp to address a memory leak in the library when init_mib() is called multiple times, so it would cause a memory leak between requests until systems have been updated with this new patch
Best regards
Tim Düsterhus 
--------------yGSIK1CwwdKdEx0hka75PUAm--