add timeouts

pull/179/head
Simon Let 4 years ago
parent 8aded88f69
commit 439e60dab8
No known key found for this signature in database
GPG Key ID: D650C65DD46D431D
  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"
"os"
"strconv"
"time"
"github.com/curusarn/resh/internal/cfg"
"github.com/curusarn/resh/internal/histfile"
@ -69,6 +70,10 @@ func (s *Server) Run() {
server := &http.Server{
Addr: "localhost:" + strconv.Itoa(s.config.Port),
Handler: mux,
ReadTimeout: 1 * time.Second,
WriteTimeout: 1 * time.Second,
ReadHeaderTimeout: 1 * time.Second,
IdleTimeout: 30 * time.Second,
}
go server.ListenAndServe()

@ -8,8 +8,8 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
"github.com/curusarn/resh/internal/httpclient"
"github.com/curusarn/resh/internal/output"
"github.com/curusarn/resh/internal/records"
"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")
client := httpclient.New()
client := http.Client{
Timeout: 1 * time.Second,
}
_, err = client.Do(req)
if err != nil {
out.FatalDaemonNotRunning(err)

@ -172,16 +172,6 @@ __resh_session_init() {
}
__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
__RESH_XDG_CACHE_HOME="$HOME/.cache/resh"
else
@ -197,5 +187,5 @@ __resh_set_xdg_home_paths() {
__RESH_XDG_DATA_HOME="$XDG_DATA_HOME/resh"
fi
mkdir -p "$__RESH_XDG_DATA_HOME" >/dev/null 2>/dev/null
export __RESH_XDG_CONFIG_FILE
export __RESH_XDG_DATA_HOME
}

Loading…
Cancel
Save