Skip to content

Commit

Permalink
set timeout when reading blocklist response
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Feb 27, 2019
1 parent b166a14 commit a1a4c73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion torrent/blocklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ func (s *Session) reloadBlocklist() error {
}()
req = req.WithContext(ctx)

resp, err := http.DefaultClient.Do(req)
client := http.Client{
Timeout: s.config.BlocklistUpdateTimeout,
}

resp, err := client.Do(req)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions torrent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Config struct {
BlocklistURL string
// When to refresh blocklist
BlocklistUpdateInterval time.Duration
// HTTP timeout for downloading blocklist
BlocklistUpdateTimeout time.Duration

// Enable RPC server
RPCEnabled bool
Expand Down Expand Up @@ -118,6 +120,7 @@ var DefaultConfig = Config{
PeerIDPrefix: "-RN" + Version + "-",
ExtensionHandshakeClientVersion: "Rain " + Version,
BlocklistUpdateInterval: 24 * time.Hour,
BlocklistUpdateTimeout: 10 * time.Minute,

// RPC Server
RPCEnabled: true,
Expand Down

0 comments on commit a1a4c73

Please sign in to comment.