MQTT重连异常

环境

  • EMQX 版本:5.0.20
  • 操作系统版本:Ubuntu 20.04.2 LTS

重现此问题的步骤

我们的客户端在刷新页面后会短时间内重连,然后会有小概率出现无法连接上emqx的问题,返回的报错信息是Not authorized如图,我们通过自己的http服务进行认证与授权,但是这个时间段并有没有相关日志,也就是好像请求并没有到我们的http服务,然后大概10几秒后就会好

EMQX 有相关日志么,然后认证的指标里面失败次数有对应增长么

2023-12-21T01:50:36.382087+00:00 [error] msg: http_connector_get_status_failed, mfa: emqx_connector_http:do_get_status/2, line: 422, reason: closed, worker: <0.2654.0>
2023-12-21T01:50:36.382682+00:00 [warning] msg: alarm_is_activated, mfa: emqx_alarm:do_actions/3, line: 416, message: <<“resource down: emqx_authz_http:3”>>, name: <<“emqx_authz_http:3”>>
2023-12-21T01:50:36.382938+00:00 [warning] msg: health_check_failed, mfa: emqx_resource_manager:handle_connected_health_check/1, line: 555, id: <<“emqx_authz_http:3”>>, status: disconnected
2023-12-21T01:50:58.185114+00:00 [error] msg: http_server_query_failed, mfa: emqx_authz_http:authorize/4, line: 113, peername: 123.157.208.9:43728, clientid: 2865ec5110a043cf9d392af090fec296, reason: {resource_error,#{msg => “resource not connected”,reason => not_connected}}, resource: <<“emqx_authz_http:3”>>
2023-12-21T01:50:58.185302+00:00 [warning] msg: cannot_publish_to_topic, mfa: emqx_channel:process_publish/2, line: 663, peername: 123.157.208.9:43728, clientid: 2865ec5110a043cf9d392af090fec296, topic: vcs/reg/0d3f1dda862f42b285ed58c5dde6d837/2865ec5110a043cf9d392af090fec296, reason: not_authorized
2023-12-21T01:51:28.199314+00:00 [error] msg: http_server_query_failed, mfa: emqx_authz_http:authorize/4, line: 113, peername: 123.157.208.9:43728, clientid: 2865ec5110a043cf9d392af090fec296, reason: {resource_error,#{msg => “resource not connected”,reason => not_connected}}, resource: <<“emqx_authz_http:3”>>
2023-12-21T01:51:28.199487+00:00 [warning] msg: cannot_publish_to_topic, mfa: emqx_channel:process_publish/2, line: 663, peername: 123.157.208.9:43728, clientid: 2865ec5110a043cf9d392af090fec296, topic: vcs/reg/0d3f1dda862f42b285ed58c5dde6d837/2865ec5110a043cf9d392af090fec296, reason: not_authorized
2023-12-21T01:51:36.384978+00:00 [warning] msg: alarm_is_deactivated, mfa: emqx_alarm:do_actions/3, line: 422, name: <<“emqx_authz_http:3”>>
2023-12-21T01:58:12.407213+00:00 [error] msg: http connector do request, received error response, mfa: emqx_connector_http:on_query/3, line: 342, peername: 127.0.0.1:41694, clientid: daed59c9870a4c5e9af29b485d20454a, connector: <<“emqx_authn_http:1”>>, request: {“/vcs/mqtt/auth/daed59c9870a4c5e9af29b485d20454a”,[{<<“accept”>>,<<“application/json”>>},{<<“cache-control”>>,<<“no-cache”>>},{<<“connection”>>,<<“keep-alive”>>},{<<“content-type”>>,<<“application/json”>>},{<<“keep-alive”>>,<<“timeout=30, max=1000”>>}],<<“{"username":"ezviz_rtc_username","password":"ezviz_rtc_password"}”>>}, status_code: 502
2023-12-21T01:58:12.407582+00:00 [error] msg: unrecoverable_error, mfa: emqx_resource_buffer_worker:handle_query_result_pure/3, line: 834, peername: 127.0.0.1:41694, clientid: daed59c9870a4c5e9af29b485d20454a, id: <<“emqx_authn_http:1”>>, reason: #{body => <<“\r\n502 Bad Gateway\r\n\r\n

502 Bad Gateway

\r\n
nginx\r\n\r\n\r\n”>>,headers => [{<<“server”>>,<<“nginx”>>},{<<“date”>>,<<“Thu, 21 Dec 2023 01:58:12 GMT”>>},{<<“content-type”>>,<<“text/html; charset=UTF-8”>>},{<<“content-length”>>,<<“150”>>},{<<“connection”>>,<<“keep-alive”>>}],status_code => 502}
2023-12-21T01:59:53.797357+00:00 [warning] msg: authorization_permission_denied, mfa: emqx_authz:authorize_non_superuser/5, line: 357, peername: 183.134.198.3:44114, clientid: 73341a96d10b40f7b86ed0da0f2051d5, topic: ezviz/waitingroom-msg/9218c7df94fd475aa82a86a11def20ac, ipaddr: {183,134,198,3}, source: http, username: undefined
这是日志,指标增长倒是不确定,也不知道之前是多少

2024-01-05T01:58:49.058137+00:00 [info] msg: authorization_permission_allowed, mfa: emqx_authz:log_allowed/1, line: 375, peername: 39.171.244.20:17284, clientid: aa7ac54a1bb44ff386d66ca925712903, topic: vcs/aa7ac54a1bb44ff386d66ca925712903, ipaddr: {39,171,244,20}, source: http, username: undefined
2024-01-05T01:58:49.068030+00:00 [info] msg: authorization_permission_allowed, mfa: emqx_authz:log_allowed/1, line: 375, peername: 39.171.244.20:17284, clientid: aa7ac54a1bb44ff386d66ca925712903, topic: vcs/reg/0d3f1dda862f42b285ed58c5dde6d837/aa7ac54a1bb44ff386d66ca925712903, ipaddr: {39,171,244,20}, source: http, username: undefined
2024-01-05T01:58:49.068854+00:00 [info] msg: authorization_permission_allowed, mfa: emqx_authz:log_allowed/1, line: 375, peername: 127.0.0.1:41784, clientid: f84a2ff8b2c74ea4970d234f340f0ab3, topic: vcs/aa7ac54a1bb44ff386d66ca925712903, ipaddr: {127,0,0,1}, source: file, username: <<“ezviz_rtc_username”>>
2024-01-05T01:58:51.031830+00:00 [info] msg: terminate, mfa: emqx_connection:terminate/2, line: 668, peername: 39.171.244.20:17284, clientid: aa7ac54a1bb44ff386d66ca925712903, reason: {shutdown,takenover}
2024-01-05T01:58:53.158106+00:00 [info] msg: terminate, mfa: emqx_connection:terminate/2, line: 668, peername: 115.236.50.10:36858, clientid: aa7ac54a1bb44ff386d66ca925712903, reason: {shutdown,takenover}
2024-01-05T01:58:54.277689+00:00 [info] msg: terminate, mfa: emqx_connection:terminate/2, line: 668, peername: 39.171.244.20:6516, clientid: aa7ac54a1bb44ff386d66ca925712903, reason: {shutdown,takenover}
2024-01-05T01:58:59.404208+00:00 [info] msg: terminate, mfa: emqx_connection:terminate/2, line: 668, peername: 123.157.208.8:16637, clientid: aa7ac54a1bb44ff386d66ca925712903, reason: {shutdown,takenover}
2024-01-05T01:59:00.520322+00:00 [info] msg: terminate, mfa: emqx_connection:terminate/2, line: 668, peername: 123.157.208.8:22963, clientid: aa7ac54a1bb44ff386d66ca925712903, reason: {shutdown,takenover}
2024-01-05T01:59:02.142241+00:00 [info] msg: terminate, mfa: emqx_connection:terminate/2, line: 668, peername: 115.236.50.10:49673, clientid: aa7ac54a1bb44ff386d66ca925712903, reason: {shutdown,takenover}
2024-01-05T01:59:03.259541+00:00 [info] msg: terminate, mfa: emqx_connection:terminate/2, line: 668, peername: 115.236.50.10:48414, clientid: aa7ac54a1bb44ff386d66ca925712903, reason: {shutdown,takenover}

请问我这个clientid 的客户端一连上就被顶是什么问题,同一时间应该就只有这个客户端在连

image
客户端报错是socket error

从日志来看,是你的认证 HTTP Server 临时掉线了

那请问这个一连上就takenover是什么问题

如果使用 clean session = false 进行连接,客户端掉线后,会话依然会在 EMQX 内维持一段时间,当客户端重连时,旧的会话内容会被新的连接接管(takenover)

但是我们这边发生的情况是,这个客户端ID崩溃后再连上就会出现重复被takenover了,但是我确定这个时间点只有一个客户端在用这个id连接