add timeouts

pull/184/head
Simon Let 4 years ago committed by Simon Let
parent baf1af938e
commit 6fbd183b3e
  1. 5
      cmd/daemon/run-server.go
  2. 6
      internal/collect/collect.go
  3. 12
      scripts/util.sh

@ -4,6 +4,7 @@ import (
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"time"
"github.com/curusarn/resh/internal/cfg" "github.com/curusarn/resh/internal/cfg"
"github.com/curusarn/resh/internal/histfile" "github.com/curusarn/resh/internal/histfile"
@ -69,6 +70,10 @@ func (s *Server) Run() {
server := &http.Server{ server := &http.Server{
Addr: "localhost:" + strconv.Itoa(s.config.Port), Addr: "localhost:" + strconv.Itoa(s.config.Port),
Handler: mux, Handler: mux,
ReadTimeout: 1 * time.Second,
WriteTimeout: 1 * time.Second,
ReadHeaderTimeout: 1 * time.Second,
IdleTimeout: 30 * time.Second,
} }
go server.ListenAndServe() go server.ListenAndServe()

@ -8,8 +8,8 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/curusarn/resh/internal/httpclient"
"github.com/curusarn/resh/internal/output" "github.com/curusarn/resh/internal/output"
"github.com/curusarn/resh/internal/records" "github.com/curusarn/resh/internal/records"
"go.uber.org/zap" "go.uber.org/zap"
@ -39,7 +39,9 @@ func SendRecord(out *output.Output, r records.Record, port, path string) {
} }
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
client := httpclient.New() client := http.Client{
Timeout: 1 * time.Second,
}
_, err = client.Do(req) _, err = client.Do(req)
if err != nil { if err != nil {
out.FatalDaemonNotRunning(err) out.FatalDaemonNotRunning(err)

@ -172,16 +172,6 @@ __resh_session_init() {
} }
__resh_set_xdg_home_paths() { __resh_set_xdg_home_paths() {
if [ -z "${XDG_CONFIG_HOME-}" ]; then
__RESH_XDG_CONFIG_FILE="$HOME/.config"
else
__RESH_XDG_CONFIG_FILE="$XDG_CONFIG_HOME"
fi
mkdir -p "$__RESH_XDG_CONFIG_FILE" >/dev/null 2>/dev/null
__RESH_XDG_CONFIG_FILE="$__RESH_XDG_CONFIG_FILE/resh.toml"
export __RESH_XDG_CONFIG_FILE
if [ -z "${XDG_CACHE_HOME-}" ]; then if [ -z "${XDG_CACHE_HOME-}" ]; then
__RESH_XDG_CACHE_HOME="$HOME/.cache/resh" __RESH_XDG_CACHE_HOME="$HOME/.cache/resh"
else else
@ -197,5 +187,5 @@ __resh_set_xdg_home_paths() {
__RESH_XDG_DATA_HOME="$XDG_DATA_HOME/resh" __RESH_XDG_DATA_HOME="$XDG_DATA_HOME/resh"
fi fi
mkdir -p "$__RESH_XDG_DATA_HOME" >/dev/null 2>/dev/null mkdir -p "$__RESH_XDG_DATA_HOME" >/dev/null 2>/dev/null
export __RESH_XDG_CONFIG_FILE export __RESH_XDG_DATA_HOME
} }

Loading…
Cancel
Save