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

cannot use multiple different error handlers in one gateway binary #1143

Closed
jgiles opened this issue Feb 29, 2020 · 3 comments
Closed

cannot use multiple different error handlers in one gateway binary #1143

jgiles opened this issue Feb 29, 2020 · 3 comments

Comments

@jgiles
Copy link
Contributor

jgiles commented Feb 29, 2020

Fill in the following sections with explanations of what's gone wrong.

Steps you follow to reproduce the error:

  1. Create ServeMux without a custom error handler. Register it to handle prefix "/v1"
  2. Create a ServeMux with a custom error handler using runtime.WithProtoErrorHandler. Register it to handle prefix "/v2".
  3. Make calls resulting in errors to a mix of v1 and v2 endpoints.

Observe that the v2 error handler runs for:

  • errors returned from the backends on both the v1 and v2 endpoints
  • errors returned from within runtime.ServeMux code (e.g. Unimplemented on unknown URIs) on the v2 endpoints

Errors from within runtime.ServeMux code (like unknown URIs) under v1 result in unexpected use of OtherErrorHandler errors.

What did you expect to happen instead:

  • v1 endpoints use the default error handler
  • v2 endpoints use the configured custom error handler.

What's your theory on why it isn't working:

  • The WithProtoErrorHandler option overwrites a global handler HTTPError and configures the global OtherErrorHandler to return "unexpected use" errors:
    HTTPError = serveMux.protoErrorHandler
  • Generated gateway handler code calls the global HTTPError regardless of the protoErrorHandler configured on the current ServeMux instance:
    runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
  • Without a configured protoErrorHandler, ServeMux falls back to the global OtherErrorHandler (which has been overwritten if any mux in the process has a protoErrorHandler configured).

An initial patch to fix this issue can be seen here: master...paxosglobal:per-mux-error-handler

However, since this does change the generated code to rely on the updated runtime code, I'd appreciate guidance on the process for handling/merging this kind of breaking change.

@jgiles
Copy link
Contributor Author

jgiles commented Feb 29, 2020

I guess a less-breaking alternative patch would be to modify DefaultHTTPError to look and see if there is a configured protoErrorHandler (and stop overwriting HTTPError when configuring protoErrorHandler). Then the current generated code continues to operate.

@jgiles
Copy link
Contributor Author

jgiles commented Feb 29, 2020

Actually, that would lead to trouble if someone tried to explicitly configure DefaultHTTPError as the proto error handler. It also means clients can't use HTTPError a custom "global fallback" error handler.

We could initialize HTTPError = muxOrGlobalErrorHandler, retain the current DefaultErrorHandler, and set var GlobalErrorHandler = DefaultErrorHandler. That would make the current generated code work, preserve the options people currently have for directly modifying HTTPError, and allow setting an alternative global fallback.

@johanbrandhorst
Copy link
Collaborator

The latter option sounds good to me, please put together a PR if you can find the time.

jgiles added a commit to paxosglobal/grpc-gateway that referenced this issue Mar 1, 2020
Support specifying different custom error handlers on different muxes,
or specifying custom error handlers on some muxes and using the default
handlers on others.

Make the runtime.HTTPError use the mux-configured error handler if
present, and allow overriding the global default behavior by setting
GlobalHTTPErrorHandler.

Add commentary explaining the use of the different options for
controlling error handling.
adasari pushed a commit to adasari/grpc-gateway that referenced this issue Apr 9, 2020
…stem#1144)

* Fix grpc-ecosystem#1143: Support multiple error handlers.

Support specifying different custom error handlers on different muxes,
or specifying custom error handlers on some muxes and using the default
handlers on others.

Make the runtime.HTTPError use the mux-configured error handler if
present, and allow overriding the global default behavior by setting
GlobalHTTPErrorHandler.

Add commentary explaining the use of the different options for
controlling error handling.

* Stop overwriting HTTPError.

* Fix WithProtoErrorHandler comment.

* Document error customization options.
pull bot pushed a commit to BuildingRobotics/grpc-gateway that referenced this issue Apr 29, 2020
…stem#1144)

* Fix grpc-ecosystem#1143: Support multiple error handlers.

Support specifying different custom error handlers on different muxes,
or specifying custom error handlers on some muxes and using the default
handlers on others.

Make the runtime.HTTPError use the mux-configured error handler if
present, and allow overriding the global default behavior by setting
GlobalHTTPErrorHandler.

Add commentary explaining the use of the different options for
controlling error handling.

* Stop overwriting HTTPError.

* Fix WithProtoErrorHandler comment.

* Document error customization options.
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

No branches or pull requests

2 participants