resgateio / resgate

A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.
https://resgate.io
MIT License
685 stars 67 forks source link

Allow service to extend request timeout #4

Closed jirenius closed 6 years ago

jirenius commented 6 years ago

Issue

When a request to a service takes a long time, there is currently no way for the service to signal back to the resgate that the request has been received and is being worked on. This may cause the request to timeout, giving the client a timeout error, even if the request has been processed.

Suggested solution

A meta response may be made by the service to any type of request. This response would contain the new desired timeout duration in milliseconds. To be easy to distinguish from the actual json response, it should not be json encoded.

It should be utf-8/latin-1 encoded and have the format timeout:"<number>". These sort of meta responses may later be extended with more key/values, using comma separation. resgate can quickly detect a meta response by analyzing the first byte - if it is a latin-1 letter, it is a meta response.

Example meta response, extending the timeout to 10 seconds:

timeout:"10000"
jirenius commented 6 years ago

branch https://github.com/jirenius/resgate/tree/feature/allow-service-to-extend-request-timeout

jirenius commented 6 years ago

Modified the format from: timeout: to timeout:"" This allowed using reflect.StructTag parsing, as well as being more flexible in case new keys are added.

jirenius commented 6 years ago

Fixed in: https://github.com/jirenius/resgate/pull/12