Skip to content

allow disabling the default golang database/sql retry behavior #899

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

Merged
merged 6 commits into from
Jul 25, 2024

Conversation

dvilaverde
Copy link
Contributor

@dvilaverde dvilaverde commented Jul 24, 2024

We've run into a problem caused by the Golangs database/sql package default retry behavior (which can't be disabled by the way) when an ErrBadConn from the database/sql/driver is returned by the driver. We're looking to have our application fail fast when an issue occurs reaching the DB, but as of now we're seeing 3 retries, causing our application to hang up longer than we'd like.

Seems like others in the community have been asking for a way to disable retries, see golang/go#52886 but the go developers have decided to not allow developers to configure that behavior.

This PR makes use of the Validator interface, along with introducing a new Driver argument called retries to determine if ErrBadConn or the go-mysql-org native ErrBadConn should be returned.

This takes advantage of the fact that retry won't occur unless the database/sql ErrBadConn is returned. Per go docs:

To prevent duplicate operations, ErrBadConn should NOT be returned if there's a possibility that the database server might have performed the operation. Even if the server sends back an error, you shouldn't return ErrBadConn.

And to maintain the behavior of discarding bad connection, the Validator interface will return false for isValid(), preventing the bad connection from being cached for reuse in sql.DB.

Thoughts on this are appreciated.


// here we issue assert that even though we only issued 1 query, that the retries
// remained on and there were 3 calls to the DB.
require.Equal(t, 3, srv.handler.queryCount)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here we had 3 calls to the server mockHandler because the database/sql package retried 3 times and retries were NOT turned off.


// here we issue assert that even though we only issued 1 query, that the retries
// remained on and there were 3 calls to the DB.
require.Equal(t, 1, srv.handler.queryCount)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same test as before but the retries were off and now there is only 1 call to the server mockHandler

mefcorvi and others added 2 commits July 24, 2024 00:06
…mysql-org#894)

After upgrading to MariaDB 11.4, the canal module stopped detecting row
updates within transactions due to incorrect handling of fake rotate events.
MariaDB 11.4 does not set LogPos for certain events, causing these events
to be ignored. This fix modifies the handling to consider fake rotate events
only for ROTATE_EVENTs with timestamp = 0, aligning with MariaDB and MySQL
documentation.
Copy link
Collaborator

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

rest lgtm

@lance6716 lance6716 merged commit ee48e78 into go-mysql-org:master Jul 25, 2024
13 checks passed
@dvilaverde dvilaverde deleted the retries branch July 25, 2024 04:04
morgo added a commit to morgo/go-mysql that referenced this pull request Jul 28, 2024
…ditional-ddls

* origin/add-additional-ddls:
  allow disabling the default golang database/sql retry behavior (go-mysql-org#899)
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.

3 participants