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

gateway: ability to set response write timeout #679

Open
lidel opened this issue Oct 1, 2024 · 0 comments
Open

gateway: ability to set response write timeout #679

lidel opened this issue Oct 1, 2024 · 0 comments
Labels
dif/easy Someone with a little familiarity can pick up effort/hours Estimated to take one or several hours help wanted Seeking public contribution on this issue P2 Medium: Good to have, but can wait until someone steps up topic/gateway Issues related to HTTP Gateway

Comments

@lidel
Copy link
Member

lidel commented Oct 1, 2024

Problem

At Shipyard we've run some A/B tests at public gateway and lowering nginx timeout from 5m to 30s.
This produced better UX and also raised the number of 200s while lowering 504s.

Right now, the boxo/gateway library does not have any timeout, aside from this failsafe 1h one, so we set timeout at .nginx is sitting in front of rainbow.

This is extra step that most of people running gateways does not do, thus wasting resources while looking for content that is not provided correctly to certain degree (nginx default timeout is 60s, while it could be lowered).

What is really unfortunate is that IPFS Desktop users hit gateway directly, and they never hit any timeout, unless it is their user agent (browser).

Proposed feature

We should introduce feature similar to nginx's proxy_read_timeout directly in the boxo/gateway library, make it configurable, but also set it to some implicit default (e.g. 30s).

It should not depend on any internal gateway logic, but solely count the time between two successful writes from server to the client.

This way everyone using boxo will save resources, and Desktop users will get meaningful error page sooner, and we will not regress.

Implementation ideas

Details tbd, but broad strokes idea for the boxo/gateway library will be to wrap existing handler in a generic response writer timeout handler:

func main() {
    gwHandler := // current boxo/gateway handler
    timeoutHandler := WithResponseWriteTimeout(gwHandler, 30*time.Second) // future handler will act like this
    http.ListenAndServe(":8080", timeoutHandler)
}
  • The WithResponseWriteTimeout middleware creates a timeoutResponseWriter and starts a timer.
    • "timeoutResponseWriter" wraps the original ResponseWriter and tracks the last successful write.
    • Every time data is written successfully, the timer is reset.
    • If no data is written for the specified duration, the timer expires, and a 504 Gateway Timeout status is sent to the client.

Configuration-wise, Config struct would get time.Duration field similar to block timeout in backend here, and NewHandler(config, backend) would set implicit default if not provided in config.

  • We should check context for list of things that node tried, and print useful error to user (i tried routing, found no peers, or found 4 pers, but all offline)
@lidel lidel added need/triage Needs initial labeling and prioritization P2 Medium: Good to have, but can wait until someone steps up dif/easy Someone with a little familiarity can pick up effort/hours Estimated to take one or several hours help wanted Seeking public contribution on this issue topic/gateway Issues related to HTTP Gateway and removed need/triage Needs initial labeling and prioritization labels Oct 1, 2024
@lidel lidel changed the title gateway: implicit write timeout gateway: ability to set response write timeout Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dif/easy Someone with a little familiarity can pick up effort/hours Estimated to take one or several hours help wanted Seeking public contribution on this issue P2 Medium: Good to have, but can wait until someone steps up topic/gateway Issues related to HTTP Gateway
Projects
None yet
Development

No branches or pull requests

1 participant