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

未關閉
#25,412 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
57/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
c, php
領域
backend

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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

主要語言
C
星號
41.8k
分支
8.6k
平均合併
2 天 15 小時
30 天內合併 PR
125

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。