插件自启动问题

我使用plugin模版创建了一个auth_mysql的插件。在dashboard里启动的时候一切正常,可以正常使用。但是当我配置成跟随pod自启动的时候,会导致pod奔溃,启动不了。
plugins {
states = [
{
name_vsn = “my_emqx_plugin-5.9.0-beta.3”, enable = true
},
{
name_vsn = “test_emqx_plugin-1.0.0”, enable = true
}
]
}

当我把这段代码启动的时候,一切正常工作。 当我配置emqx,这个插件自启动的时候,会导致pod启动失败 2025-04-28T01:14:28.275838+00:00 [debug] msg: ensure_local_table, table: emqx_channel_registry, ‘$span’: {complete,true} 2025-04-28T01:14:28.275954+00:00 [info] msg: starting_rlog_shard, shard: emqx_cm_shard 2025-04-28T01:14:28.276280+00:00 [info] msg: Shard fully up, node: ‘emqx@emqx-core-58556659c5-0.emqx-headless.emqx.svc.cluster.local’, shard: emqx_cm_shard 2025-04-28T01:14:28.276503+00:00 [debug] msg: mria_mnesia_create_table, name: emqx_activated_alarm, options: [{type,ordered_set},{storage,disc_copies},{local_content,true},{record_name,activated_alarm},{attributes,[name,details,message,activate_at]}] 2025-04-28T01:14:28.277016+00:00 [debug] msg: ensure_local_table, table: emqx_activated_alarm, ‘$span’: start 2025-04-28T01:14:28.277115+00:00 [debug] msg: ensure_local_table, table: emqx_activated_alarm, ‘$span’: {complete,true} 2025-04-28T01:14:28.277197+00:00 [debug] msg: mria_mnesia_create_table, name: emqx_deactivated_alarm, options: [{type,ordered_set},{storage,disc_copies},{local_content,true},{record_name,deactivated_alarm},{attributes,[activate_at,name,details,message,deactivate_at]}] 2025-04-28T01:14:28.277639+00:00 [debug] msg: ensure_local_table, table: emqx_deactivated_alarm, ‘$span’: start 2025-04-28T01:14:28.277711+00:00 [debug] msg: ensure_local_table, table: emqx_deactivated_alarm, ‘$span’: {complete,true} Listener tcp:default is NOT started due to: disabled. Listener ssl:default on :8883 started. Listener ws:default is NOT started due to: disabled. Listener wss:default is NOT started due to: disabled. 2025-04-28T01:14:28.281584+00:00 [debug] msg: started_apps, apps: [os_mon,hocon,lc,emqx] 2025-04-28T01:14:28.281677+00:00 [debug] msg: starting_app, app: emqx_plugins 2025-04-28T01:14:28.298627+00:00 [debug] msg: started_plugin_apps, apps: [map_sets,my_emqx_plugin] 插件正在加载: test_emqx_plugin size_object: matchstate term not allowed[os_mon] cpu supervisor port (cpu_sup): Erlang has closed [os_mon] memory supervisor port (memsup): Erlang has closed

load(Env) →
io:format(“插件正在加载: ~p~n”, [?MODULE]),

%% 启动MySQL连接
case start_mysql_connection() of
    {ok, Conn} ->
        %% 保存连接到应用环境
        application:set_env(test_emqx_plugin, mysql_conn, Conn),
        io:format("MySQL连接已建立~n"),

        %% 注册所有钩子函数
        hook('client.authenticate', {?MODULE, on_client_authenticate, [Env]}),
        hook('client.authorize', {?MODULE, on_client_authorize, [Env]});
    {error, Reason} ->
        io:format("MySQL连接失败: ~p~n", [Reason]),
        {error, {mysql_connect_failed, Reason}}
end.

%% 启动MySQL连接
start_mysql_connection() →
%% 确保mysql应用已启动
application:ensure_all_started(mysql),

%% 建立MySQL连接
mysql:start_link([
    {host, ?MYSQL_HOST},
    {port, ?MYSQL_PORT},
    {user, ?MYSQL_USER},
    {password, ?MYSQL_PASS},
    {database, ?MYSQL_DB},
    {keep_alive, true},
    {name, {local, ?MYSQL_CONN}}
]).

{deps,
%% Not all plugins have to depend on emqx
[
%% but if they do, use git_subdir in the default profile.
%% Normally, emqx is needed as a dependency only if the plugin
%% wants to use some records defined in emqx.
{emqx,
{git_subdir, “https://github.com/emqx/emqx.git”, {tag, “e5.9.0-beta.1”}, “apps/emqx”}},
{emqx_ctl,
{git_subdir, “https://github.com/emqx/emqx.git”, {tag, “e5.9.0-beta.1”},
“apps/emqx_ctl”}},
{emqx_utils,
{git_subdir, “https://github.com/emqx/emqx.git”, {tag, “e5.9.0-beta.1”},
“apps/emqx_utils”}},
{emqx_durable_storage,
{git_subdir, “https://github.com/emqx/emqx.git”, {tag, “e5.9.0-beta.1”},
“apps/emqx_durable_storage”}},
{emqx_ds_backends,
{git_subdir, “https://github.com/emqx/emqx.git”, {tag, “e5.9.0-beta.1”},
“apps/emqx_ds_backends”}},
{emqx_ds_builtin_local,
{git_subdir, “https://github.com/emqx/emqx.git”, {tag, “e5.9.0-beta.1”},
“apps/emqx_ds_builtin_local”}},
{emqx_ds_builtin_raft,
{git_subdir, “https://github.com/emqx/emqx.git”, {tag, “e5.9.0-beta.1”},
“apps/emqx_ds_builtin_raft”}},
{emqx_plugins,
{git_subdir, “https://github.com/emqx/emqx.git”, {tag, “e5.9.0-beta.1”},
“apps/emqx_plugins”}},
%% this is my plugin’s dependency
{map_sets, “1.1.0”},

% {ecpool, {git, “https://github.com/emqx/ecpool”, {tag, “0.6.1”}}},
{poolboy, “1.5.2”},
{mysql, “1.7.0”},
{mysql_poolboy, “.*”, {git, “https://github.com/mysql-otp/mysql-otp-poolboy”,
{tag, “0.2.1”}}}

]}.

{plugins, [
{erlang_qq, {git, “https://github.com/k32/erlang_qq.git”, {tag, “1.0.0”}}},
{emqx_plugrel, {git, “https://github.com/emqx/emqx_plugrel.git”, {tag, “0.6.2”}}},
{erlfmt, “1.6.0”}
]}.

{erl_opts, [debug_info]}.

%% this is the release version, different from app vsn in .app file
{relx, [
{release, {test_emqx_plugin, “1.0.0”}, [
test_emqx_plugin,
map_sets,
mysql
% mysql_poolboy
]},
{dev_mode, false},
{include_erts, false},
{include_src, false}
]}.

-module(test_emqx_plugin_sup).

-include(“test_emqx_plugin.hrl”).

-behaviour(supervisor).

-export([start_link/0]).

-export([init/1]).

start_link() →
supervisor:start_link({local, ?MODULE}, ?MODULE, ).

init() →
{ok, {{one_for_all, 0, 1}, }}.

节点角色:core

版本信息:5.8.6 (Open Source)

The size_object: matchstate term not allowed error can happen when you run Elixir 1.17 compiled with OTP 27 on OTP 26. The assumption is that this somehow happened here.

v5.8.6 是 OTP 26 的,你最好用 26 ,不要用 27 编。
你用的 plugins 模板 master里面的.toolversion应该是用的是 0tp27,他是适配 5.9.0 的

所以我升级到5.9就可以了吗

5.9 还没有发布。

那么模版哪个分支是OTP26呢?

没有 26 的,建议你直接改.tool_version,然后模块里面有不兼容的就自己改改。

这个 commit 之前是用的 OTP25(5.7),也可以用于 26.