-
Notifications
You must be signed in to change notification settings - Fork 72
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
Error class refactoring (part 2) #41
Error class refactoring (part 2) #41
Conversation
1ce8eda
to
49952df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
@@ -995,6 +1014,12 @@ void Init_cext() | |||
Trilogy_TimeoutError = rb_const_get(Trilogy, rb_intern("TimeoutError")); | |||
rb_global_variable(&Trilogy_TimeoutError); | |||
|
|||
Trilogy_BaseConnectionError = rb_const_get(Trilogy, rb_intern("BaseConnectionError")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have given this feedback in the previous PR 😓, but should we rename this ConnectionError
? I find the "Base" prefix a little out of place as nothing inherits this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hey @jhawthorn ! Yeah unfortunately the naming is a little weird at the moment because we're handling some of the new error classification via modules to preserve backwards compatibility. (See "Backward compatibility" in the original issue).
We currently have ConnectionError
defined as a module, so that consumers could do rescue Trilogy::ConnectionError
to rescue connection-related errors, while existing code could retain compatibility if they're doing rescue IOError
, etc.
Is there a better name we could use for the class itself, other than BaseConnectionError
? Or perhaps we ought to be sticking with a better naming convention, foregoing backwards compatibility, and working towards a v3.0 instead with these changes?
Still seeing pretty consistent failures for |
3a98328
to
fa214fa
Compare
I can get failures running via the CI docker files: MYSQL_VERSION=8 DOCKERFILE=Dockerfile.test.buster script/cibuild But it doesn't fail consistently even with the same seed. I've seen failures running just that one test, but seems to fail more often when I run the full suite. I also tried running in a loop and it seems to either fail on the first iteration or succeed for the whole loop: def test_connection_error
1000.times do |i|
p i
Trilogy.new(
:host => "db.local",
:port => 3306,
:username => "foo",
:password => nil,
:ssl => true,
:ssl_mode => 4,
:tls_min_version => 3
).close
rescue Trilogy::BaseConnectionError => e
end
end Same story on main before the error changes. It looks like when the test passes we read an err packet, and when it fails we read an auth switch packet, so that's something: https://github.com/github/trilogy/blob/10aee3ba880af40658ad19d3a9ff09a57adada01/src/client.c#L432-L440 I think we can remove this test for now and add it back once we've addressed the flakiness. |
Or maybe this? #42 |
548d300
to
1fbe282
Compare
1fbe282
to
b54138b
Compare
@composerinteralia @jhawthorn would love to get your help to move this along!
Let me know if there's anything else you'd like me to address 😄 |
#41 added a translation of `ECONNREFUSED` and `ECONNRESET` to `Trilogy::BaseConnectionError`. We've got a few places at GitHub where we explicitly rescue these errors (or `SystemCallError`). Although it is possible to rework those rescues to check for particular error messages (like trilogy-libraries/activerecord-trilogy-adapter@03c1610), it'd be a bit easier if we could maintain compatibility. I also worry that checking for specific error messages could be a bit brittle. This commit introduces two new Trilogy errors, which inherit from the corresponding `Errno` errors. We've already done something like this for `Errno::ETIMEDOUT`. This keeps Trilogy compatible with GitHub's existing rescues, while still raising something that is a `Trilogy::Error` and a `Trilogy::ConnectionError` (although NOT a `Trilogy::BaseConnectionError` anymore). A downside to this approach is that we might end up with a lot of Trilogy-specific `Errno` subclasses. If that gets annoying perhaps we could revisit when it comes time for a major release. Another approach might be a single `Trilogy::SystemCallError` that inherits from `SystemCallError` and then keeps a reference to the underlying `Errno` error.
Follow up to: #15
Converts a few more Trilogy errors:
TRILOGY_DNS_ERROR
is generally returned when we attempt to connect to a db with an unknown hostname, which we should treat as a connection error and handle properly in the adapter.Trilogy::ConnectionClosed
was introduced in the last PR to handleIOError
, but I forgot to actually raise the Trilogy error in the C ext, so that's been updatedECONNREFUSED
andECONNRESET
, which should both be handled as connection errors. These are the ones I've been encountering frequently; we can expand on the error conversions as we see more pop up. I'm not sure how many of the 107 syscall errors we actually expect to see.I plan to update trilogy-libraries/activerecord-trilogy-adapter#24 to handle these changes.