-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Update REST Client to Support Custom R/W Timeouts #4285
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#4263 RestServer#Start now takes read and write timeout arguments. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#4263 Add `--read-timeout` and `--write-timeout` args to the `rest-server` command | ||
to support custom RPC R/W timeouts. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"net" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/rakyll/statik/fs" | ||
|
@@ -45,20 +46,22 @@ func NewRestServer(cdc *codec.Codec) *RestServer { | |
Mux: r, | ||
CliCtx: cliCtx, | ||
Cdc: cdc, | ||
|
||
log: logger, | ||
log: logger, | ||
} | ||
} | ||
|
||
// Start starts the rest server | ||
func (rs *RestServer) Start(listenAddr string, maxOpen int) (err error) { | ||
func (rs *RestServer) Start(listenAddr string, maxOpen int, readTimeout, writeTimeout uint) (err error) { | ||
server.TrapSignal(func() { | ||
err := rs.listener.Close() | ||
rs.log.Error("error closing listener", "err", err) | ||
}) | ||
|
||
cfg := rpcserver.DefaultConfig() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you dropping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there is no longer a need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see - fair enough |
||
cfg.MaxOpenConnections = maxOpen | ||
cfg := &rpcserver.Config{ | ||
MaxOpenConnections: maxOpen, | ||
ReadTimeout: time.Duration(readTimeout) * time.Second, | ||
WriteTimeout: time.Duration(writeTimeout) * time.Second, | ||
} | ||
|
||
rs.listener, err = rpcserver.Listen(listenAddr, cfg) | ||
if err != nil { | ||
|
@@ -87,8 +90,12 @@ func ServeCommand(cdc *codec.Codec, registerRoutesFn func(*RestServer)) *cobra.C | |
registerRoutesFn(rs) | ||
|
||
// Start the rest server and return error if one exists | ||
err = rs.Start(viper.GetString(client.FlagListenAddr), | ||
viper.GetInt(client.FlagMaxOpenConnections)) | ||
err = rs.Start( | ||
viper.GetString(client.FlagListenAddr), | ||
viper.GetInt(client.FlagMaxOpenConnections), | ||
uint(viper.GetInt(client.FlagRPCReadTimeout)), | ||
uint(viper.GetInt(client.FlagRPCWriteTimeout)), | ||
) | ||
|
||
return err | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the timeout in order to receive conformation that your write request was successful? Like what is a rest write?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rigelrozanski yeah, the write timeout, from the REST client pov, is mainly for broadcasting.