Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mqtt-bridge): avoid middleman process #9870

Merged
merged 5 commits into from
Jan 31, 2023

Conversation

keynslug
Copy link
Contributor

Instead, supervise emqtt client process directly. New scheme should be much simpler than before.

This currently has some minor drawbacks.

  • Bridge will survive intermittent network problems worse than before: the resource manager will try to restart the bridge only after a ReconnectInterval number of seconds, during this window a number of messages will probably be lost.

EMQX-8798

So that buffer worker would notice a connection loss in time, and
recycle inflight messages subsequently.
@keynslug keynslug force-pushed the fix/mqtt-connection-loss-feedback branch 2 times, most recently from 8e4a13d to 1bb0945 Compare January 31, 2023 13:10
Instead, supervise `emqtt` client process directly.
@keynslug keynslug force-pushed the fix/mqtt-connection-loss-feedback branch from 1bb0945 to 30cb2f2 Compare January 31, 2023 15:10
@keynslug keynslug force-pushed the fix/mqtt-connection-loss-feedback branch from 30cb2f2 to c5a7cd5 Compare January 31, 2023 15:30
@keynslug keynslug marked this pull request as ready for review January 31, 2023 16:00
@keynslug keynslug requested review from a team, thalesmg and JimMoen as code owners January 31, 2023 16:00
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 4055660402

  • 71 of 107 (66.36%) changed or added relevant lines in 3 files are covered.
  • 27 unchanged lines in 13 files lost coverage.
  • Overall coverage increased (+0.04%) to 80.29%

Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/emqx_connector/src/emqx_connector_mqtt.erl 10 16 62.5%
apps/emqx_connector/src/mqtt/emqx_connector_mqtt_worker.erl 59 89 66.29%
Files with Coverage Reduction New Missed Lines %
apps/emqx_authn/src/enhanced_authn/emqx_enhanced_authn_scram_mnesia.erl 1 86.57%
apps/emqx_connector/src/emqx_connector_mqtt.erl 1 67.12%
apps/emqx_gateway/src/emqx_gateway_schema.erl 1 90.91%
apps/emqx_machine/src/emqx_machine.erl 1 79.31%
apps/emqx/src/emqx_flapping.erl 1 85.11%
apps/emqx/src/emqx_limiter/src/emqx_limiter_server.erl 1 89.08%
apps/emqx/src/emqx_router_helper.erl 1 86.27%
apps/emqx/src/emqx_session.erl 1 87.6%
apps/emqx/src/emqx_channel.erl 2 87.11%
apps/emqx/src/emqx_stats.erl 2 91.67%
Totals Coverage Status
Change from base Build 4054246154: 0.04%
Covered Lines: 23362
Relevant Lines: 29097

💛 - Coveralls

{ok, WorkerPid}.
case emqx_connector_mqtt_worker:send_to_remote_async(InstanceId, Msg, Callback) of
ok ->
% TODO this is racy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emqx_connector_mqtt_worker:send_to_remote_async/3 can return {ok, Pid} ?

Fun()
catch
error:badarg ->
maps:get(badarg, Else);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems all badargs are mapped to disconnected, maybe simply return disconnected when badarg happens.

catch
error:badarg ->
maps:get(badarg, Else);
exit:{noproc, _} ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is noproc just a race condition of badarg ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if yes, it should return disconnected too ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly, AFAICS. This is what gen:call will throw when there's no pid behind a name, even when the gproc act as a registry.

if yes, it should return disconnected too ?

On a second glance the code seems a bit too complicated, so probably yes. I'll open a followup PR.

@zmstone zmstone merged commit b3ad9e9 into emqx:release-50 Jan 31, 2023
@zmstone
Copy link
Member

zmstone commented Jan 31, 2023

minor comment fix can be fixed in follow-up PRs.

@keynslug keynslug deleted the fix/mqtt-connection-loss-feedback branch January 31, 2023 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants