Skip to content

Commit

Permalink
services/horizon: Ignore ConnectionTimeout in txsub (#2818)
Browse files Browse the repository at this point in the history
This commit changes the behaviour of `--connection-timeout` config
param. After this change, it is ignored in `txsub` so if the value is
less than 30s, `txsub` will still timeout after 30s.

If Horizon admin wants to set `--connection-timeout` to a small value it
will likely affect `txsub` system because it requires at least 5 seconds
on average to report the status of the transaction when it's included in
the ledger.

Currently the code ignores timeout for all `POST` requests to avoid
having to parse the route from request URL.
  • Loading branch information
bartekn authored Jul 15, 2020
1 parent 59324f1 commit 9af0422
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).x
- `core-db-max-open-connections`
- `core-db-max-idle-connections`
* HAL response population is implemented using Go `strings` package instead of `regexp`, improving its performance.
* The `--connection-timeout` param is ignored in `POST /transactions`. The requests sent to that endpoint will always timeout after 30 seconds.

## v1.5.0

Expand Down
2 changes: 1 addition & 1 deletion services/horizon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ var configOpts = support.ConfigOptions{
OptType: types.Int,
FlagDefault: 55,
CustomSetValue: support.SetDuration,
Usage: "defines the timeout of connection after which 504 response will be sent or stream will be closed, if Horizon is behind a load balancer with idle connection timeout, this should be set to a few seconds less that idle timeout",
Usage: "defines the timeout of connection after which 504 response will be sent or stream will be closed, if Horizon is behind a load balancer with idle connection timeout, this should be set to a few seconds less that idle timeout, does not apply to POST /transactions",
},
&support.ConfigOption{
Name: "per-hour-rate-limit",
Expand Down
5 changes: 4 additions & 1 deletion services/horizon/internal/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ func timeoutMiddleware(timeout time.Duration) func(next http.Handler) http.Handl
}
}()

r = r.WithContext(ctx)
// txsub has a custom timeout
if r.Method != http.MethodPost {
r = r.WithContext(ctx)
}
next.ServeHTTP(mw, r)
}
return http.HandlerFunc(fn)
Expand Down

0 comments on commit 9af0422

Please sign in to comment.