Skip to content

Conversation

@v0idpwn
Copy link
Contributor

@v0idpwn v0idpwn commented May 3, 2024

This is inspired in how GRPC go approaches HTTP errors when performing GRPC requests.

Error translation is useful in different situations. For example, AWS load balancer replies with a 504 when there are no live instances. There, a unavailable error is much more fitting than internal.

For go translation table: https://github.com/grpc/grpc-go/blob/273fe145d03df516018cf4642e6987e027ffc0f5/internal/transport/http_util.go#L68

v0idpwn added 2 commits May 3, 2024 08:57
This is inspired in how GRPC go approaches HTTP errors when performing
GRPC requests.

This provides meaningful errors in different situations. For example, AWS
load balancer replies with a 504 when there are no live instances.
There, a `unavailable` error is much more fitting than `internal`.
@v0idpwn
Copy link
Contributor Author

v0idpwn commented May 3, 2024

I didn't find where these errors are handled in Mint (if they are), so I didn't touch it. I'm not using Mint either.

Copy link
Contributor

@polvalente polvalente left a comment

Choose a reason for hiding this comment

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

Verbs should be changed and tests need to be added

end

def from_status(401), do: exception(GRPC.Status.unauthorized(), status_message(401))
def from_status(401), do: exception(GRPC.Status.unauthenticated(), status_message(401))
Copy link
Contributor

Choose a reason for hiding this comment

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

401 is unauthorized as per HTTP specs

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we should use the same verbs as HTTP if we are to do any kind of translation here

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, shouldn't the mint client also have similar changes?

Copy link
Contributor Author

@v0idpwn v0idpwn May 3, 2024

Choose a reason for hiding this comment

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

Hi, @polvalente. There's only so much we can do without adding new errors to the library. As the GRPC specification states only 16 error codes, what we do is only a best effort. I copied all the matching pairs from the official implementation in Go

Copy link
Contributor Author

@v0idpwn v0idpwn May 4, 2024

Choose a reason for hiding this comment

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

Hi, @polvalente. I managed to write tests, but found that adding the status handling to the mint adapter is quite complex due to current adapter structure. Can't we perhaps open an issue for a mint implementation of this feature in the future? Maybe someone with a better grasp of the mint adapter (or even future me) can take it

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather have them being feature-equivalent as one is meant to be a drop-in replacement of the other.

Can you elaborate on what made it difficult to add this kind of handling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Essentially, the status is received at ConnectionProcess, which is called to start the request, but the calling process reads the response from the StreamResponseProcess. Meaning I'd need to write some process coordination or rework current coordination logic. Since I don't fully understand the current architecture decisions (yet?), I found this a bit challenging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

client_adapters = [GRPC.Client.Adapters.Gun, GRPC.Client.Adapters.Mint]

for {http_code, expected_error_code} <- error_table, client_adapter <- client_adapters do
test "#{client_adapter} returns RPC Error when getting HTTP #{http_code}" do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure where I should put these tests

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems fine

@sleipnir
Copy link
Collaborator

@v0idpwn any progress here?

@v0idpwn
Copy link
Contributor Author

v0idpwn commented Jun 19, 2024

Hi, @sleipnir. I did an attempt at implementing it on the mint adapter, but ended up hitting a wall. I'll give it another stab soonish.

@polvalente
Copy link
Contributor

@v0idpwn do you plan on continue this work?

@sleipnir
Copy link
Collaborator

sleipnir commented Nov 7, 2025

ping @v0idpwn

@sleipnir
Copy link
Collaborator

sleipnir commented Nov 7, 2025

@v0idpwn and @polvalente I reread this thread and took a look at the code. I confess I'm not very familiar with the client-side code, but let's try something.

To keep the current architecture untouched, the smallest / least invasive approach is:

When ConnectionProcess receives the initial headers and they do not include a non-zero grpc-status, and a previously stored HTTP status for that request is ≥ 400:

Translate the HTTP status to a matching gRPC error code (aligned with gun behavior)

Inject a synthetic grpc-status (and optional grpc-message) into the headers before passing them to StreamResponseProcess

This way:

  • We avoid cross-process coordination
  • StreamResponseProcess continues untouched
  • Errors like 504 → gRPC UNAVAILABLE now propagate correctly
  • Feature parity with the Gun adapter is preserved

We should also add tests that validate:

  • HTTP error status without gRPC trailers triggers the translated gRPC error
  • Existing grpc-status is never overridden
  • Normal success path stays unchanged

The whole thing should happen more or less around here:

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