Skip to content

Commit

Permalink
timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Oct 13, 2023
1 parent 8e5e1bd commit 680b198
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions rpc/websockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net"
"net/http"
"sync"
"time"

"github.com/cosmos/cosmos-sdk/client"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -47,6 +48,13 @@ import (

const (
messageSizeLimit = 32 * 1024 * 1024 // 32MB

)

var (
readTimeout = 15 * time.Second // Time to read the request
writeTimeout = 15 * time.Second // Time to write the response
idleTimeout = 60 * time.Second // Max time for connections using TCP Keep-Alive
)

type WebsocketsServer interface {
Expand Down Expand Up @@ -111,13 +119,21 @@ func (s *websocketsServer) Start() {
ws := mux.NewRouter()
ws.Handle("/", s)

// configuring the HTTP server
server := &http.Server{
Addr: s.wsAddr,
Handler: ws,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
IdleTimeout: idleTimeout,
}

go func() {
var err error
/* #nosec G114 -- http functions have no support for timeouts */
if s.certFile == "" || s.keyFile == "" {
err = http.ListenAndServe(s.wsAddr, ws)
err = server.ListenAndServe()
} else {
err = http.ListenAndServeTLS(s.wsAddr, s.certFile, s.keyFile, ws)
err = server.ListenAndServeTLS(s.certFile, s.keyFile)
}

if err != nil {
Expand Down

0 comments on commit 680b198

Please sign in to comment.