Skip to content

Commit 719aafb

Browse files
Adding timeout when fetching plugin
1 parent e4a92a1 commit 719aafb

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

internal/config/plugin_installer.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sort"
1212
"strings"
1313
"sync"
14+
"time"
1415

1516
"github.com/blang/semver"
1617
"github.com/micro-editor/json5"
@@ -129,7 +130,10 @@ func (pc PluginChannels) Fetch(out io.Writer) PluginPackages {
129130

130131
// Fetch retrieves all available PluginPackages from the given channel
131132
func (pc PluginChannel) Fetch(out io.Writer) PluginPackages {
132-
resp, err := http.Get(string(pc))
133+
client := http.Client {
134+
Timeout: 30 * time.Second,
135+
}
136+
resp, err := client.Get(string(pc))
133137
if err != nil {
134138
fmt.Fprintln(out, "Failed to query plugin channel:\n", err)
135139
return nil
@@ -149,7 +153,10 @@ func (pc PluginChannel) Fetch(out io.Writer) PluginPackages {
149153

150154
// Fetch retrieves all available PluginPackages from the given repository
151155
func (pr PluginRepository) Fetch(out io.Writer) PluginPackages {
152-
resp, err := http.Get(string(pr))
156+
client := http.Client {
157+
Timeout: 30 * time.Second,
158+
}
159+
resp, err := client.Get(string(pr))
153160
if err != nil {
154161
fmt.Fprintln(out, "Failed to query plugin repository:\n", err)
155162
return nil
@@ -405,7 +412,10 @@ func GetInstalledPluginVersion(name string) string {
405412
// DownloadAndInstall downloads and installs the given plugin and version
406413
func (pv *PluginVersion) DownloadAndInstall(out io.Writer) error {
407414
fmt.Fprintf(out, "Downloading %q (%s) from %q\n", pv.pack.Name, pv.Version, pv.Url)
408-
resp, err := http.Get(pv.Url)
415+
client := http.Client {
416+
Timeout: 30 * time.Second,
417+
}
418+
resp, err := client.Get(pv.Url)
409419
if err != nil {
410420
return err
411421
}

0 commit comments

Comments
 (0)