diff --git a/cmd_serve.go b/cmd_serve.go index 6fd8e5b..4ee73d3 100644 --- a/cmd_serve.go +++ b/cmd_serve.go @@ -86,7 +86,13 @@ func runServe(dataDir, seed string, testnet bool, rpcBind, rpcPort, walletRPC st addr := rpcBind + ":" + rpcPort core.Print(nil, "Go daemon RPC on %s (syncing from %s)", addr, seed) - httpSrv := &http.Server{Addr: addr, Handler: srv} + httpSrv := &http.Server{ + Addr: addr, + Handler: srv, + ReadTimeout: 30 * time.Second, + WriteTimeout: 120 * time.Second, + IdleTimeout: 120 * time.Second, + } go func() { <-ctx.Done() httpSrv.Close() diff --git a/config/file.go b/config/file.go index c547474..3a7e544 100644 --- a/config/file.go +++ b/config/file.go @@ -46,14 +46,14 @@ func DefaultFileConfig() FileConfig { // // cfg.LoadFromEnv() func (c *FileConfig) LoadFromEnv() { - if v := os.Getenv("LNS_MODE"); v != "" { c.Network = v } - if v := os.Getenv("DAEMON_SEED"); v != "" { c.Seed = v } - if v := os.Getenv("CHAIN_DATADIR"); v != "" { c.DataDir = v } - if v := os.Getenv("RPC_PORT"); v != "" { c.RPCPort = v } - if v := os.Getenv("RPC_BIND"); v != "" { c.RPCBind = v } - if v := os.Getenv("HSD_URL"); v != "" { c.HSDUrl = v } - if v := os.Getenv("HSD_API_KEY"); v != "" { c.HSDKey = v } - if v := os.Getenv("DNS_PORT"); v != "" { c.DNSPort = v } + if v := core.Env("LNS_MODE"); v != "" { c.Network = v } + if v := core.Env("DAEMON_SEED"); v != "" { c.Seed = v } + if v := core.Env("CHAIN_DATADIR"); v != "" { c.DataDir = v } + if v := core.Env("RPC_PORT"); v != "" { c.RPCPort = v } + if v := core.Env("RPC_BIND"); v != "" { c.RPCBind = v } + if v := core.Env("HSD_URL"); v != "" { c.HSDUrl = v } + if v := core.Env("HSD_API_KEY"); v != "" { c.HSDKey = v } + if v := core.Env("DNS_PORT"); v != "" { c.DNSPort = v } } // IsTestnet returns true if configured for testnet. diff --git a/service.go b/service.go index 8df937a..58ea120 100644 --- a/service.go +++ b/service.go @@ -111,7 +111,7 @@ func (s *BlockchainService) start() core.Result { addr := s.opts.RPCBind + ":" + s.opts.RPCPort go func() { core.Print(nil, "blockchain RPC on %s", addr) - http.ListenAndServe(addr, s.daemon) + (&http.Server{Addr: addr, Handler: s.daemon, ReadTimeout: 30 * time.Second, WriteTimeout: 120 * time.Second}).ListenAndServe() }() core.Print(nil, "blockchain service started (testnet=%v, seed=%s)", s.opts.Testnet, s.opts.Seed)