ext/enchant: abort when PHP starts twice in a process with libenchant 2.8
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
php/php-src 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)未关闭Extension: openssl Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
Bug Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
SNMP accepts malformed remote ports可能已有人在做 @somethingwithproof 于 21 天前认领。 未关闭
难度 2/5 半天 新手友好度 62/100
维护者通常 1 天内回复
-
Bug Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
相似的 Issue
-
interpreter-core type-bug
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
ImageMagick/ImageMagick6#490 ·
-
难度 1/5 1 小时以内 新手友好度 62/100
camera-2018/hdu-cs-wiki#647 ·
-
ZIP/ZIPS decode dereferences NULL when the cached libdeflate decompressor can't be allocated (3.5 regression)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
AcademySoftwareFoundation/openexr#2884 ·
维护者通常 1 天内回复