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

fix: infinite recursion in mysql connector and improve mysql EE bridge tests #9571

Merged
merged 6 commits into from Dec 22, 2022

Conversation

olcai
Copy link
Contributor

@olcai olcai commented Dec 17, 2022

This is a continuation of EMQX-7923 and implements further EE mysql bridge tests covering:

  • prepared statements
  • batching
  • driver behavior with timeout failures

A bug was found while implementing tests regarding prepared statements. An infinite loop was triggered in the mysql connector when a query used a prepared statement key that was not among the defined prepared statements on start. We now check that the key is defined among the prepared statements before recursing. It seems that this bug was never
triggered in any production code.

Fixes EMQX-8414.

PR Checklist

Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:

  • Added tests for the changes
  • Changed lines covered in coverage report
  • Change log has been added to changes/ dir
  • For internal contributor: there is a jira ticket to track this change

@olcai olcai marked this pull request as ready for review December 20, 2022 12:59
@olcai olcai requested a review from zmstone as a code owner December 20, 2022 12:59
@olcai olcai requested a review from thalesmg December 20, 2022 12:59
changes/v5.0.13-zh.md Outdated Show resolved Hide resolved
thalesmg
thalesmg previously approved these changes Dec 20, 2022
lib-ee/emqx_ee_bridge/test/emqx_ee_bridge_mysql_SUITE.erl Outdated Show resolved Hide resolved
@olcai olcai requested a review from thalesmg December 21, 2022 14:17
thalesmg
thalesmg previously approved these changes Dec 21, 2022
apps/emqx_connector/src/emqx_connector_mysql.erl Outdated Show resolved Hide resolved
@@ -305,6 +315,8 @@ prepare_sql_to_conn(Conn, [{Key, SQL} | PrepareList]) when is_pid(Conn) ->
?SLOG(info, LogMeta#{result => success}),
prepare_sql_to_conn(Conn, PrepareList);
{error, Reason} ->
% FIXME: we should try to differ on transient failers and
Copy link
Member

Choose a reason for hiding this comment

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

Possible to fix now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took a shot at it but came to the conclusion that it might require a more thorough refactor. The code is hard to follow as-is and already has several layers of error coping mechanisms, and these should be unified. Created EMQX-8582 to track it.

olcai and others added 6 commits December 22, 2022 10:27
An infinite loop was triggered in the mysql connector when a query
used a prepared statement key that was not among the defined prepared
statements on start. We now check that the key is defined among the
prepared statements before recursing. It seems that this bug was never
triggered in any production code flow and simply found while writing
tests.

An error return spell fix is also included as well as a FIXME comment
regarding running mysql:prepare and not distinguishing between
transient failures and syntax errors. Syntax errors should not be
retried.
Co-authored-by: Thales Macedo Garitezi <thalesmg@gmail.com>
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 3756578837

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • 31 unchanged lines in 11 files lost coverage.
  • Overall coverage increased (+0.07%) to 79.562%

Files with Coverage Reduction New Missed Lines %
apps/emqx_gateway/src/mqttsn/emqx_sn_channel.erl 1 73.04%
apps/emqx/src/emqx_cm.erl 1 89.91%
apps/emqx/src/emqx_connection.erl 1 88.18%
apps/emqx/src/emqx_os_mon.erl 1 84.06%
apps/emqx/src/emqx_alarm.erl 2 91.82%
apps/emqx/src/emqx_channel.erl 2 87.17%
apps/emqx_gateway/src/exproto/emqx_exproto_gcli.erl 3 48.78%
apps/emqx/src/emqx_listeners.erl 3 85.48%
apps/emqx/src/emqx_broker.erl 4 82.42%
apps/emqx/src/emqx_sys_mon.erl 5 86.46%
Totals Coverage Status
Change from base Build 3748356601: 0.07%
Covered Lines: 22544
Relevant Lines: 28335

💛 - Coveralls

@zmstone
Copy link
Member

zmstone commented Dec 22, 2022

the slim build fails will be fixed in another PR.

@zmstone zmstone merged commit c678770 into emqx:master Dec 22, 2022
@olcai olcai deleted the improve-mysql-bridge-test branch December 22, 2022 18:10
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

6 participants