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

Clean up trilogy error translation #50891

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

composerinteralia
Copy link
Member

This commit makes a few changes to our trilogy error translation:

  • Introduce EOFError and make SyscallError < ConnectionError trilogy-libraries/trilogy#118 introduced Trilogy::EOFError which we can use instead of matching on TRILOGY_CLOSED_CONNECTION.
  • Refactor error classes trilogy-libraries/trilogy#15 introduced Trilogy::ConnectionClosed, which inherits from IOError for backwards compatibility. As far as I can tell that's the only IOError trilogy can raise, so this commit rescues the trilogy-specific error instead.
  • As far as I can tell Trilogy does not raise SocketError, so don't bother translating that
  • Don't treat TRILOGY_UNEXPECTED_PACKET as a connection error. If we get this, it's probably a bug in trilogy that we should fix. I'd like to eventually get rid of TRILOGY_INVALID_SEQUENCE_ID too, but we're currently relying on it in a few tests (related to trilogy missing caching_sha2_password auth support, if I recall correctly)

I'm kinda hoping we'll eventually be able to simplify this to something like:

if exception.is_a?(Trilogy::ConnectionError)
  ConnectionFailed.new(message, connection_pool: @pool)
else
  super
end

but we'd need more changes to trilogy before that is possible.

This commit makes a few changes to our trilogy error translation:

* trilogy-libraries/trilogy#118 introduced
  `Trilogy::EOFError` which we can use instead of matching on
  `TRILOGY_CLOSED_CONNECTION`.
* trilogy-libraries/trilogy#15 introduced
  `Trilogy::ConnectionClosed`, which inherits from `IOError` for
  backwards compatibility. As far as I can tell that's the only
  `IOError` trilogy can raise, so this commit rescues the
  trilogy-specific error instead.
* As far as I can tell Trilogy does not raise `SocketError`, so don't
  bother translating that
* Don't treat TRILOGY_UNEXPECTED_PACKET as a connection error. If we get
  this, it's probably a bug in trilogy that we should fix. I'd like to
  eventually get rid of TRILOGY_INVALID_SEQUENCE_ID too, but we're
  currently relying on it in a few tests (related to trilogy missing
  caching_sha2_password auth support, if I recall correctly)

I'm kinda hoping we'll eventually be able to simplify this to something
like:

```rb
if exception.is_a?(Trilogy::ConnectionError)
  ConnectionFailed.new(message, connection_pool: @pool)
else
  super
end
```

but we'd need more changes to trilogy before that is possible.
@rafaelfranca rafaelfranca merged commit 91f4fdc into rails:main Jan 26, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants