EMQx 创建规则 提示 500

环境信息

  • EMQ X 版本:4.3.5
  • 操作系统及版本:linux
  • 其他

问题描述

EMQx 创建规则 提示 500

参数:

{
	"rawsql": "SELECT\n  payload.msg as msg\nFROM\n  \"t/#\"\nWHERE\n  msg = 'hello'",
	"actions": [{
		"name": "data_to_webserver",
		"params": {
			"method": "POST",
			"path": "",
			"headers": {
				"content-type": "application/json"
			},
			"body": "",
			"$resource": "resource:347639"
		},
		"fallbacks": []
	}],
	"description": "",
	"ctx": {
		"clientid": "c_emqx",
		"username": "u_emqx",
		"topic": "t/a",
		"qos": 1,
		"payload": "{\"msg\": \"hello\"}"
	},
	"id": "rule:394704"
}

配置文件及日志

2021-08-18T18:08:59.412323+08:00 [error] POST /api/v4/rules error: {{{bad_type,{rule,<<"rule:518498">>,[<<"$events/client_connected">>],<<"SELECT clientid FROM \"$events/client_connect"...>>,false,[{var,<<"clientid">>}],[],{},{},continue,[{action_instance,<<"data"...>>,data_to_webserver,...}],true,1629281339411,<<>>,normal}},[{emqx_rule_registry,trans,2,[{file,"emqx_rule_registry.erl"},{line,480}]},{emqx_rule_registry,handle_call,3,[{file,"emqx_rule_registry.erl"},{line,443}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,715}]},{gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,744}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]},{gen_server,call,[emqx_rule_registry,{add_rules,[{rule,<<"rule:518498">>,[<<"$events/client_conne"...>>],<<"SELECT clientid FROM"...>>,false,[{var,<<...>>}],[],{},{},...}]},10000]}}, stacktrace:, [{gen_server,call,3,[{file,"gen_server.erl"},{line,246}]},{emqx_rule_engine,create_rule,1,[{file,"emqx_rule_engine.erl"},{line,186}]},{emqx_rule_engine_api,do_create_rule,1,[{file,"emqx_rule_engine_api.erl"},{line,214}]},{minirest_handler,dispatch,2,[{file,"minirest_handler.erl"},{line,84}]},{minirest,handle_request,2,[{file,"minirest.erl"},{line,116}]},{minirest,init,2,[{file,"minirest.erl"},{line,108}]},{cowboy_handler,execute,2,[{file,"cowboy_handler.erl"},{line,41}]},{cowboy_stream_h,execute,3,[{file,"cowboy_stream_h.erl"},{line,320}]},{cowboy_stream_h,request_process,3,[{file,"cowboy_stream_h.erl"},{line,302}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]

日志中报错的规则是 518498 ,创建报错的是 394704,这两个并不是同一个业务行为。看下在创建规则的时候,后台错误日志是什么?


报错

2021-08-19T11:05:24.419017+08:00 [error] Generic server emqx_rule_registry terminating. Reason: {{bad_type,{rule,<<"rule:032750">>,[<<"t/#">>],<<"SELECT\n  payload.msg as msg\nFROM\n  \"t/#\"\nWHERE\n "...>>,false,[{as,{path,[{key,<<"payload">>},{key,<<"msg">>}]},{var,<<"msg">>}}],[],{},{'=',{var,<<"msg">>},{const,<<"hello">>}},continue,[{action_instance,<<"inspect_"...>>,inspect,[],...}],true,1629342324418,<<>>,normal}},[{emqx_rule_registry,trans,2,[{file,"emqx_rule_registry.erl"},{line,480}]},{emqx_rule_registry,handle_call,3,[{file,"emqx_rule_registry.erl"},{line,443}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,715}]},{gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,744}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}. Last message: {add_rules,[{rule,<<"rule:032750">>,[<<"t/#">>],<<"SELECT\n  payload.msg as msg\nFROM\n  \"t/#\"\nWHERE\n "...>>,false,[{as,{path,[{key,<<"payload">>},{key,<<"msg">>}]},{var,<<"msg">>}}],[],{},{'=',{var,<<"msg">>},{const,<<"hello">>}},continue,[{action_instance,<<"inspect_"...>>,inspect,[],...}],true,1629342324418,<<>>,normal}]}. State: #{}. Client <0.8916.7> stacktrace: [{gen,do_call,4,[{file,"gen.erl"},{line,208}]},{gen_server,call,3,[{file,"gen_server.erl"},{line,242}]},{emqx_rule_engine,create_rule,1,[{file,"emqx_rule_engine.erl"},{line,186}]},{emqx_rule_engine_api,do_create_rule,1,[{file,"emqx_rule_engine_api.erl"},{line,214}]}].
2021-08-19T11:05:24.419541+08:00 [error] crasher: initial call: emqx_rule_registry:init/1, pid: <0.8795.7>, registered_name: emqx_rule_registry, error: {{bad_type,{rule,<<"rule:032750">>,[<<"t/#">>],<<"SELECT\n  payload.msg as msg\nFROM\n  \"t/#\"\nWHERE\n "...>>,false,[{as,{path,[{key,<<"payload">>},{key,<<"msg">>}]},{var,<<"msg">>}}],[],{},{'=',{var,<<"msg">>},{const,<<"hello">>}},continue,[{action_instance,<<"inspect_"...>>,inspect,[],...}],true,1629342324418,<<>>,normal}},[{emqx_rule_registry,trans,2,[{file,"emqx_rule_registry.erl"},{line,480}]},{emqx_rule_registry,handle_call,3,[{file,"emqx_rule_registry.erl"},{line,443}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,715}]},{gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,744}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}, ancestors: [emqx_rule_engine_sup,<0.1776.0>], message_queue_len: 0, messages: [], links: [<0.1777.0>], dictionary: [], trap_exit: false, status: running, heap_size: 10958, stack_size: 28, reductions: 16941; neighbours:
2021-08-19T11:05:24.420113+08:00 [error] Supervisor: {local,emqx_rule_engine_sup}. Context: child_terminated. Reason: {{bad_type,{rule,<<"rule:032750">>,[<<"t/#">>],<<"SELECT\n  payload.msg as msg\nFROM\n  \"t/#\"\nWHERE\n "...>>,false,[{as,{path,[{key,<<"payload">>},{key,<<"msg">>}]},{var,<<"msg">>}}],[],{},{'=',{var,<<"msg">>},{const,<<"hello">>}},continue,[{action_instance,<<"inspect_"...>>,inspect,[],...}],true,1629342324418,<<>>,normal}},[{emqx_rule_registry,trans,2,[{file,"emqx_rule_registry.erl"},{line,480}]},{emqx_rule_registry,handle_call,3,[{file,"emqx_rule_registry.erl"},{line,443}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,715}]},{gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,744}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}. Offender: id=emqx_rule_registry,pid=<0.8795.7>.
2021-08-19T11:05:24.420290+08:00 [error] POST /api/v4/rules error: {{{bad_type,{rule,<<"rule:032750">>,[<<"t/#">>],<<"SELECT\n  payload.msg as msg\nFROM\n  \"t/#\"\nWHE"...>>,false,[{as,{path,[{key,<<"payl"...>>},{key,<<...>>}]},{var,<<"msg">>}}],[],{},{'=',{var,<<"msg">>},{const,<<"hell"...>>}},continue,[{action_instance,<<"insp"...>>,inspect,...}],true,1629342324418,<<>>,normal}},[{emqx_rule_registry,trans,2,[{file,"emqx_rule_registry.erl"},{line,480}]},{emqx_rule_registry,handle_call,3,[{file,"emqx_rule_registry.erl"},{line,443}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,715}]},{gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,744}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]},{gen_server,call,[emqx_rule_registry,{add_rules,[{rule,<<"rule:032750">>,[<<"t/#">>],<<"SELECT\n  payload.msg"...>>,false,[{as,{...},...}],[],{},{...},...}]},10000]}}, stacktrace:, [{gen_server,call,3,[{file,"gen_server.erl"},{line,246}]},{emqx_rule_engine,create_rule,1,[{file,"emqx_rule_engine.erl"},{line,186}]},{emqx_rule_engine_api,do_create_rule,1,[{file,"emqx_rule_engine_api.erl"},{line,214}]},{minirest_handler,dispatch,2,[{file,"minirest_handler.erl"},{line,90}]},{minirest,handle_request,2,[{file,"minirest.erl"},{line,116}]},{minirest,init,2,[{file,"minirest.erl"},{line,108}]},{cowboy_handler,execute,2,[{file,"cowboy_handler.erl"},{line,41}]},{cowboy_stream_h,execute,3,[{file,"cowboy_stream_h.erl"},{line,320}]},{cowboy_stream_h,request_process,3,[{file,"cowboy_stream_h.erl"},{line,302}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]

升级到 4.3.7 也不可以

暂时没有看出问题。方便提供一下你的业务流程吗?创建了哪些资源,资源属性是?创建的规则是?我们会安排测试复现bug。

我先通过配置 emqx_web_hook.conf 方式实现吧