@@ -25,6 +25,13 @@ const (
2525 viewHelp
2626)
2727
28+ const (
29+ sparklineSize = 15
30+ graphHistorySize = 300
31+ memHistorySize = 60
32+ globalFetchTimeout = 10 * time .Second
33+ )
34+
2835type Config struct {
2936 Interval time.Duration
3037 SlowThreshold time.Duration
@@ -62,10 +69,6 @@ type certFetcher interface {
6269 DialTLSCertificates (ctx context.Context , hosts []string ) []fetcher.CertificateInfo
6370}
6471
65- const sparklineSize = 15
66- const graphHistorySize = 300
67- const memHistorySize = 60
68-
6972type App struct {
7073 fetcher fetcher.Fetcher
7174 config Config
@@ -797,24 +800,30 @@ func (a *App) doTick() tea.Cmd {
797800
798801func (a * App ) doFetch () tea.Cmd {
799802 return func () tea.Msg {
800- snap , err := a .fetcher .Fetch (context .Background ())
803+ ctx , cancel := context .WithTimeout (context .Background (), globalFetchTimeout )
804+ defer cancel ()
805+ snap , err := a .fetcher .Fetch (ctx )
801806 return fetchMsg {snap : snap , err : err }
802807 }
803808}
804809
805810func (a * App ) doRestart () tea.Cmd {
806811 return func () tea.Msg {
812+ ctx , cancel := context .WithTimeout (context .Background (), globalFetchTimeout )
813+ defer cancel ()
807814 if r , ok := a .fetcher .(restarter ); ok {
808- return restartResultMsg {err : r .RestartWorkers (context . Background () )}
815+ return restartResultMsg {err : r .RestartWorkers (ctx )}
809816 }
810817 return restartResultMsg {}
811818 }
812819}
813820
814821func (a * App ) doFetchConfig () tea.Cmd {
815822 return func () tea.Msg {
823+ ctx , cancel := context .WithTimeout (context .Background (), globalFetchTimeout )
824+ defer cancel ()
816825 if cf , ok := a .fetcher .(configFetcher ); ok {
817- raw , err := cf .FetchConfig (context . Background () )
826+ raw , err := cf .FetchConfig (ctx )
818827 return configFetchMsg {raw : raw , err : err }
819828 }
820829 return configFetchMsg {err : fmt .Errorf ("config inspection not supported" )}
@@ -834,7 +843,8 @@ func (a *App) doFetchCertificates() tea.Cmd {
834843 return certFetchMsg {err : fmt .Errorf ("certificate inspection not supported" )}
835844 }
836845
837- ctx := context .Background ()
846+ ctx , cancel := context .WithTimeout (context .Background (), globalFetchTimeout )
847+ defer cancel ()
838848 all := make ([]fetcher.CertificateInfo , 0 )
839849
840850 all = append (all , cf .FetchPKICertificates (ctx )... )
0 commit comments