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

Introduce EOFError and make SyscallError < ConnectionError #118

Merged
merged 2 commits into from
Sep 14, 2023

Conversation

jhawthorn
Copy link
Member

This makes two of the changes there seems to be consensus around from #113

First this introduces EOFError, which represents TRILOGY_CLOSED_CONNECTION. It's a subclass of BaseConnectionError, but distinct from ConnectionClosed (which represents an explicit .close from the client's side).

Second this makes Trilogy::SyscallError::* all include the ConnectionError module, allowing rescue ConnectionError to catch most types of network communication issue.

This is a new Ruby error to represent the TRILOGY_CLOSED_CONNECTION
status code, which is the status returned when read returns 0, write
hits an EPIPE, or when attempting to communicate through a socket after
it was shutdown/closed due to a previous error.

This subclasses BaseConnectionError so that it can be caught by `rescue
Trilogy::ConnectionError` (which is what we'd like to recommend for
detecting network/communication issues) and will always include the
TRILOGY_CLOSED_CONNECTION as part of the message for backwards
compatibility, as that's how currently Rails and others have been
detecting it.

Previously this would have been raised as a QueryError.
@@ -112,7 +112,13 @@ class SSLError < BaseError
include ConnectionError
end

# Raised on attempt to use connection which was explicitly closed by the user
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! I've been confused by this in the past.

@jhawthorn jhawthorn merged commit 6c6cd9f into trilogy-libraries:main Sep 14, 2023
12 checks passed
composerinteralia added a commit to composerinteralia/rails that referenced this pull request Jan 26, 2024
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.
composerinteralia added a commit to composerinteralia/rails that referenced this pull request Jan 26, 2024
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.
viralpraxis pushed a commit to viralpraxis/rails that referenced this pull request Mar 24, 2024
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.
fractaledmind pushed a commit to fractaledmind/rails that referenced this pull request May 13, 2024
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.
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.

2 participants