@@ -416,7 +416,9 @@ func (b *Bot) httpPkgEnsureZigDownloadCached(version, versionKind, fname string)
416
416
}
417
417
fmt .Fprintf (logWriter , "fetch: %s > %s\n " , url , filePath )
418
418
419
- resp , err := httpGet (url , 60 * time .Second )
419
+ ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
420
+ defer cancel ()
421
+ resp , err := httpGet (ctx , url )
420
422
if err != nil {
421
423
return errors .Wrap (err , "Get" )
422
424
}
@@ -634,7 +636,9 @@ func (b *Bot) httpPkgZigIndexCached() ([]byte, error) {
634
636
}
635
637
636
638
// Fetch the latest upstream Zig index.json
637
- resp , err := httpGet ("https://ziglang.org/download/index.json" , 60 * time .Second )
639
+ ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
640
+ defer cancel ()
641
+ resp , err := httpGet (ctx , "https://ziglang.org/download/index.json" )
638
642
if err != nil {
639
643
return nil , errors .Wrap (err , "fetching upstream https://ziglang.org/download/index.json" )
640
644
}
@@ -646,7 +650,9 @@ func (b *Bot) httpPkgZigIndexCached() ([]byte, error) {
646
650
647
651
// Fetch the Mach index.json which contains Mach nominated versions, but is otherwise not as
648
652
// up-to-date as ziglang.org's version.
649
- resp , err = httpGet ("https://machengine.org/zig/index.json" , 60 * time .Second )
653
+ ctx , cancel = context .WithTimeout (context .Background (), time .Minute )
654
+ defer cancel ()
655
+ resp , err = httpGet (ctx , "https://machengine.org/zig/index.json" )
650
656
if err != nil {
651
657
return nil , errors .Wrap (err , "fetching mach https://machengine.org/zig/index.json" )
652
658
}
@@ -714,9 +720,7 @@ func (b *Bot) httpPkgZigIndexCached() ([]byte, error) {
714
720
}
715
721
716
722
// Like http.Get, but actually respects a timeout instead of leaking a goroutine to forever run.
717
- func httpGet (url string , timeout time.Duration ) (* http.Response , error ) {
718
- ctx , cancel := context .WithTimeout (context .Background (), timeout )
719
- defer cancel ()
723
+ func httpGet (ctx context.Context , url string ) (* http.Response , error ) {
720
724
req , err := http .NewRequestWithContext (ctx , "GET" , url , nil )
721
725
if err != nil {
722
726
return nil , err
0 commit comments