Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:23862 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86291 invoked by uid 1010); 2 Jun 2006 05:49:10 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 86276 invoked from network); 2 Jun 2006 05:49:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jun 2006 05:49:10 -0000 X-PHP-List-Original-Sender: steph@zend.com X-Host-Fingerprint: 192.38.9.232 gw2.emini.dk Linux 2.4/2.6 Received: from ([192.38.9.232:13658] helo=gw2.emini.dk) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id BA/93-22639-351DF744 for ; Fri, 02 Jun 2006 01:49:08 -0400 Received: from foxbox (IGLD-84-228-79-24.inter.net.il [84.228.79.24]) by gw2.emini.dk (Postfix) with ESMTP id 90B05B4A2A; Fri, 2 Jun 2006 07:49:02 +0200 (CEST) Message-ID: <0bd201c68607$f0109730$6602a8c0@foxbox> Reply-To: "Steph Fox" To: "Dmitry Stogov" Cc: "'internals'" References: <006001c6856e$1ccafe40$6e02a8c0@thinkpad> Date: Fri, 2 Jun 2006 07:46:45 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0BCF_01C68618.B281B5A0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Subject: Re: [PHP-DEV] tsrm_shutdown() and the CLI SAPI From: steph@zend.com ("Steph Fox") ------=_NextPart_000_0BCF_01C68618.B281B5A0 Content-Type: text/plain; format=flowed; charset="Windows-1252"; reply-type=original Content-Transfer-Encoding: 7bit Hi Dmitry, Have some diagnostics: 1) zend_shutdown() is called before anything in TSRM. It invokes zend_hash_graceful_reverse_destroy(&module_registry); 2) module_destructor() is invoked via the hash-destroyer (being part of the module_registry hash constructor). This performs the MSHUTDOWN routine for each registered module, which in several cases (now) includes a PHP-side call to ts_free_id(). The ts_free_id() call usually allows the next stage to be unproblematic; it also marks the module's entry in the resource table as 'done', so that the final clearing loop won't try to double-free it. However, ts_free_id() doesn't check for 'done' itself before it frees resources. 3) DL_UNLOAD (an alias for FreeLibrary, under doze) is then called on any module loaded via dl() or php.ini (checking for a module handle)... it looks like this stage might only have happened under Macs on CLI until mid-March... 4) tsrm_shutdown() - the final clearing loop - is called via the end of the various SAPI source files (in this case, php_cli.c), and any resource that hasn't been freed explicitly by this point is freed there. It won't help our particular situation, but I think automatically calling ts_free_id() on dl-loaded modules would be better than either blanket avoidance of tsrm_shutdown() or requiring each module to call ts_free_id() explicitly during MINIT. Patch(es) to do that in PHP_5_2 branch attached. The problem in PHP-GTK is we're crashing when the compiler_globals dtor is called in tsrm_shutdown(), rather than when the gtk_globals dtor is called. I think this is a ZE problem rather than ours, but see what you think: somehow, in compiler_globals_dtor(), compiler_globals->class_table != GLOBAL_CLASS_TABLE and the compiler_globals->class_table is destroyed and freed because of that. - Steph ----- Original Message ----- From: "Dmitry Stogov" To: "'Steph Fox'" Cc: "'internals'" Sent: Thursday, June 01, 2006 1:25 PM Subject: RE: [PHP-DEV] tsrm_shutdown() and the CLI SAPI > Patch was cutted. > > Dmitry. > >> -----Original Message----- >> From: Dmitry Stogov [mailto:dmitry@zend.com] >> Sent: Thursday, June 01, 2006 3:05 PM >> To: 'Andi Gutmans'; 'Steph Fox'; 'Frank M. Kromann' >> Cc: 'internals'; 'Antony Dovgal'; 'Xuefer' >> Subject: RE: [PHP-DEV] tsrm_shutdown() and the CLI SAPI >> >> >> Hi Stepth, >> >> I reproduced crash of php-gtk on linix with php-zts. >> I mean running "php -v" then php.ini contains >> "extension=gtk2.so". The crash occurs only then php compiled >> with --enable-debug. >> >> The reason of the crash is a bug in ZE that is activated by >> memory leaks in php-gtk. In case of "php -v" we don't do >> request startup/shutdown and as result we don't handle memory >> leaks on request shutdown. During tsrm_shutdown() >> shutdow_nmemory_manager() is called after sapi_shutdown() and >> as result we cannot access sapi_globals then trying to print >> information about memory leaks and crashes. >> >> The solution - don't print information about memory leaks >> during tsrm_shutdown(). >> >> Patch for PHP_5_2 is attached, but it can be manually applied >> to any version. >> >> Steph, does you crash(es) go away with this patch? >> >> I am going to commit patch in 24h. >> Any objections? >> >> Thanks. Dmitry. >> >> > -----Original Message----- >> > From: Andi Gutmans [mailto:andi@zend.com] >> > Sent: Thursday, June 01, 2006 10:29 AM >> > To: Steph Fox; Frank M. Kromann >> > Cc: 'internals'; 'Antony Dovgal'; Dmitry Stogov; 'Xuefer' >> > Subject: Re: [PHP-DEV] tsrm_shutdown() and the CLI SAPI >> > >> > >> > As we are not planning to release a new version within the next >> > couple of weeks, I suggest before jumping to conclusions we >> > take a look at it. >> > >> > If you really need to comment out that line in the meanwhile >> > that's OK with me. >> > >> > Andi >> > >> > At 09:50 PM 5/31/2006, Steph Fox wrote: >> > >>>Yes, it would, given the root cause - but would you >> really want to >> > >>>break the whole of PHP for an academic exercise? >> > >> >> > >>It's not really an academic exercise. If we know there's a bug >> > >>someplace we should at least look into it and try and >> understand it. >> > > >> > >Frank's referring to Zeev's three-years-ago decision to simply opt >> > >out of tsrm_shutdown() here... he's suggesting we revert it. >> > > >> > >>Then if we decide to remove the trsm_shutdown call for a >> good reason >> > >>(circular dependency, blah blah blah) then we can do that >> and put a >> > >>nice fat comment on why it's the right thing to do. But I >> do think >> > >>it's benefical to try and understand what's happening. >> > > >> > >Fine, but breaking working code while you're trying to understand >> > >what's happening is far from beneficial to our users. Can't >> > we at least #0 it? >> > > >> > >> >> > >>Andi >> > >> > -- >> > PHP Internals - PHP Runtime Development Mailing List >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > >> > >> > > > __________ NOD32 1.1380 (20060125) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > -------------------------------------------------------------------------------- > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > __________ NOD32 1.1380 (20060125) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > ------=_NextPart_000_0BCF_01C68618.B281B5A0 Content-Type: text/plain; format=flowed; name="Zend_dl_dtor.txt"; reply-type=original Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Zend_dl_dtor.txt" Index: Zend/zend_API.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /repository/ZendEngine2/zend_API.c,v=0A= retrieving revision 1.296.2.27.2.13=0A= diff -u -r1.296.2.27.2.13 zend_API.c=0A= --- Zend/zend_API.c 27 May 2006 20:16:53 -0000 1.296.2.27.2.13=0A= +++ Zend/zend_API.c 2 Jun 2006 05:27:09 -0000=0A= @@ -32,6 +32,7 @@=0A= =0A= /* these variables are true statics/globals, and have to be mutex'ed on = every access */=0A= static int module_count=3D0;=0A= +static int dl_module_count=3D0;=0A= ZEND_API HashTable module_registry;=0A= =0A= /* this function doesn't check for too many parameters */=0A= @@ -1831,6 +1832,8 @@=0A= =0A= void module_destructor(zend_module_entry *module)=0A= {=0A= + int table_size;=0A= +=0A= TSRMLS_FETCH();=0A= =0A= if (module->type =3D=3D MODULE_TEMPORARY) {=0A= @@ -1852,6 +1855,8 @@=0A= #if HAVE_LIBDL || defined(HAVE_MACH_O_DYLD_H)=0A= #if !(defined(NETWARE) && defined(APACHE_1_BUILD))=0A= if (module->handle) {=0A= + table_size =3D tsrm_table_size() + 1;=0A= + ts_free_id(table_size - zend_dl_module_reverse());=0A= DL_UNLOAD(module->handle);=0A= }=0A= #endif=0A= @@ -1899,6 +1904,12 @@=0A= return ++module_count;=0A= }=0A= =0A= +/* return the dl module count */=0A= +int zend_dl_module_reverse(void)=0A= +{=0A= + return ++dl_module_count;=0A= +}=0A= +=0A= static zend_class_entry *do_register_internal_class(zend_class_entry = *orig_class_entry, zend_uint ce_flags TSRMLS_DC)=0A= {=0A= zend_class_entry *class_entry =3D malloc(sizeof(zend_class_entry));=0A= Index: Zend/zend_API.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /repository/ZendEngine2/zend_API.h,v=0A= retrieving revision 1.207.2.8.2.2=0A= diff -u -r1.207.2.8.2.2 zend_API.h=0A= --- Zend/zend_API.h 25 May 2006 10:01:06 -0000 1.207.2.8.2.2=0A= +++ Zend/zend_API.h 2 Jun 2006 05:12:12 -0000=0A= @@ -160,6 +160,7 @@=0A= #endif=0A= =0A= int zend_next_free_module(void);=0A= +int zend_dl_module_reverse(void);=0A= =0A= BEGIN_EXTERN_C()=0A= ZEND_API int zend_get_parameters(int ht, int param_count, ...);=0A= ------=_NextPart_000_0BCF_01C68618.B281B5A0 Content-Type: text/plain; format=flowed; name="TSRM_dl_dtor.txt"; reply-type=original Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="TSRM_dl_dtor.txt" Index: TSRM/TSRM.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /repository/TSRM/TSRM.c,v=0A= retrieving revision 1.68.2.3=0A= diff -u -r1.68.2.3 TSRM.c=0A= --- TSRM/TSRM.c 14 Mar 2006 15:16:07 -0000 1.68.2.3=0A= +++ TSRM/TSRM.c 2 Jun 2006 05:06:49 -0000=0A= @@ -542,7 +542,7 @@=0A= =0A= while (p) {=0A= if (p->count > j && p->storage[j]) {=0A= - if (resource_types_table && resource_types_table[j].dtor) {=0A= + if (resource_types_table && resource_types_table[j].dtor && = !resource_types_table[j].done) {=0A= resource_types_table[j].dtor(p->storage[j], &p->storage);=0A= }=0A= free(p->storage[j]);=0A= @@ -586,6 +586,12 @@=0A= #endif=0A= }=0A= =0A= +/* Obtain the current resource table size */=0A= +TSRM_API int tsrm_table_size(void)=0A= +{=0A= + return id_count;=0A= +}=0A= +=0A= =0A= /* Allocate a mutex */=0A= TSRM_API MUTEX_T tsrm_mutex_alloc(void)=0A= Index: TSRM/TSRM.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /repository/TSRM/TSRM.h,v=0A= retrieving revision 1.50.2.2=0A= diff -u -r1.50.2.2 TSRM.h=0A= --- TSRM/TSRM.h 14 Mar 2006 15:16:07 -0000 1.50.2.2=0A= +++ TSRM/TSRM.h 2 Jun 2006 05:06:43 -0000=0A= @@ -127,6 +127,7 @@=0A= =0A= /* utility functions */=0A= TSRM_API THREAD_T tsrm_thread_id(void);=0A= +TSRM_API int tsrm_table_size(void);=0A= TSRM_API MUTEX_T tsrm_mutex_alloc(void);=0A= TSRM_API void tsrm_mutex_free(MUTEX_T mutexp);=0A= TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp);=0A= ------=_NextPart_000_0BCF_01C68618.B281B5A0--