ext/enchant: abort when PHP starts twice in a process with libenchant 2.8

Offen
#25,412 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
57/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
c, php
Bereich
backend

Rechercherichtung

Start with the Enchant extension's MINIT function, referenced in the issue, and trace how its module handle is unloaded during PHP shutdown and startup. Reproduce the two-start embed case with libenchant 2.8; done means the process prints “ok” twice without GLib errors or aborting. The issue suggests retaining the extension handle, but that approach needs review.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Description

The following code, built against the embed SAPI and run with extension=enchant in php.ini:

#include <sapi/embed/php_embed.h>

int main(int argc, char **argv)
{
	for (int i = 0; i < 2; i++) {
		PHP_EMBED_START_BLOCK(argc, argv)
		zend_eval_string("enchant_broker_init(); echo \"ok\\n\";", NULL, "repro");
		PHP_EMBED_END_BLOCK()
	}

	return 0;
}

Resulted in this output, and the process aborts:

ok

(process:164148): GLib-GObject-CRITICAL **: 09:58:25.468: cannot register existing type 'EnchantProvider'

(process:164148): GLib-CRITICAL **: 09:58:25.468: g_once_init_leave: assertion 'result != 0' failed

(process:164148): GLib-GObject-ERROR **: 09:58:25.468: cannot create new instance of invalid (non-instantiatable) type '<invalid>'

But I expected this output instead:

ok
ok

libenchant is written in Vala since 2.7.0 and registers GLib types the first time a broker is created. php_module_shutdown() unloads enchant.so and libenchant with it, but GLib is linked with -z nodelete and keeps these types. The next php_module_startup() loads libenchant again, which registers them a second time: GLib refuses, and creating the broker aborts.

An embedder that restarts PHP in its process hits this. I found it with FrankenPHP, which does so to restart its workers or to reload its configuration (php/frankenphp#2834): on Ubuntu 26.04, the first use of enchant after a restart kills the server.

With ZEND_DONT_UNLOAD_MODULES=1 in the environment, the program prints ok twice. The extension could keep itself loaded by dropping its handle, as OPcache does for its own, which gives the same result here:

 PHP_MINIT_FUNCTION(enchant)
 {
+	/* GLib keeps the types libenchant registers: the library can't be loaded twice */
+	enchant_module_entry.handle = NULL;
+
 	enchant_broker_ce = register_class_EnchantBroker();
PHP Version
PHP 8.5.12 (cli) (built: Nov 12 2026 09:52:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies

Same on master (bc2d2fcc7cb).

Operating System

Ubuntu 26.04, with libenchant 2.8.2 and GLib 2.88.0

Vorherrschende Sprache
C
Sterne
41.8k
Forks
8.6k
Ø Merge
2 T. 15 Std.
Gemergte PRs (30 T.)
125

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus php/php-src

Alle Issues in php/php-src

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.