@@ -37,6 +37,7 @@ import (
3737 "github.com/google/syzkaller/prog"
3838 _ "github.com/google/syzkaller/sys"
3939 "github.com/google/syzkaller/sys/targets"
40+ "golang.org/x/sync/errgroup"
4041)
4142
4243// This is especially slightly longer than syzkaller rebuild period.
@@ -832,15 +833,19 @@ func (mgr *Manager) uploadBuildAssets(buildInfo *dashapi.Build, assetFolder stri
832833 return ret , nil
833834}
834835
835- func (mgr * Manager ) httpGET (path string ) (resp * http.Response , err error ) {
836+ func (mgr * Manager ) httpGET (ctx context. Context , path string ) (resp * http.Response , err error ) {
836837 addr := mgr .managercfg .HTTP
837838 if addr != "" && addr [0 ] == ':' {
838839 addr = "127.0.0.1" + addr // in case addr is ":port"
839840 }
840841 client := & http.Client {
841842 Timeout : time .Hour ,
842843 }
843- return client .Get (fmt .Sprintf ("http://%s%s" , addr , path ))
844+ req , err := http .NewRequestWithContext (ctx , "GET" , fmt .Sprintf ("http://%s%s" , addr , path ), nil )
845+ if err != nil {
846+ return nil , err
847+ }
848+ return client .Do (req )
844849}
845850
846851func (mgr * Manager ) uploadCoverReport () error {
@@ -860,7 +865,7 @@ func (mgr *Manager) uploadCoverReport() error {
860865 }
861866 defer buildSem .Signal ()
862867
863- resp , err := mgr .httpGET ("/cover" )
868+ resp , err := mgr .httpGET (context . Background (), "/cover" )
864869 if err != nil {
865870 return fmt .Errorf ("failed to get report: %w" , err )
866871 }
@@ -896,7 +901,8 @@ func (mgr *Manager) uploadCoverJSONLToGCS(ctx context.Context, mgrSrc, gcsDest s
896901 }
897902 defer buildSem .Signal ()
898903
899- resp , err := mgr .httpGET (mgrSrc )
904+ eg , egCtx := errgroup .WithContext (ctx )
905+ resp , err := mgr .httpGET (egCtx , mgrSrc )
900906 if err != nil {
901907 return fmt .Errorf ("failed to httpGet %s: %w" , mgrSrc , err )
902908 }
@@ -909,10 +915,8 @@ func (mgr *Manager) uploadCoverJSONLToGCS(ctx context.Context, mgrSrc, gcsDest s
909915 }
910916
911917 pr , pw := io .Pipe ()
912- defer pr .Close ()
913- go func () {
914- var closeError error
915- defer func () { pw .CloseWithError (closeError ) }()
918+ eg .Go (func () error {
919+ defer pw .Close ()
916920 var w io.Writer
917921 w = pw
918922 if compress {
@@ -923,19 +927,23 @@ func (mgr *Manager) uploadCoverJSONLToGCS(ctx context.Context, mgrSrc, gcsDest s
923927 decoder := json .NewDecoder (resp .Body )
924928 for decoder .More () {
925929 if err := f (w , decoder ); err != nil {
926- closeError = fmt .Errorf ("callback: %w" , err )
927- return
930+ return fmt .Errorf ("callback: %w" , err )
928931 }
929932 }
930- }()
931- fileName := fmt .Sprintf ("%s/%s-%s-%d-%d.jsonl" ,
932- mgr .mgrcfg .DashboardClient ,
933- mgr .name , curTime .Format (time .DateOnly ),
934- curTime .Hour (), curTime .Minute ())
935- if err := uploadFile (ctx , gcsDest , fileName , pr , publish ); err != nil {
936- return fmt .Errorf ("failed to uploadFileGCS(): %w" , err )
937- }
938- return nil
933+ return nil
934+ })
935+ eg .Go (func () error {
936+ defer pr .Close ()
937+ fileName := fmt .Sprintf ("%s/%s-%s-%d-%d.jsonl" ,
938+ mgr .mgrcfg .DashboardClient ,
939+ mgr .name , curTime .Format (time .DateOnly ),
940+ curTime .Hour (), curTime .Minute ())
941+ if err := uploadFile (egCtx , gcsDest , fileName , pr , publish ); err != nil {
942+ return fmt .Errorf ("uploadFile: %w" , err )
943+ }
944+ return nil
945+ })
946+ return eg .Wait ()
939947}
940948
941949func (mgr * Manager ) uploadCoverStat (fuzzingMinutes int ) error {
@@ -1043,13 +1051,13 @@ func uploadFile(ctx context.Context, dstPath, name string, file io.Reader, publi
10431051 log .Logf (0 , "uploading %v to %v" , name , URLStr )
10441052 if strings .HasPrefix (URLStr , "http://" ) ||
10451053 strings .HasPrefix (URLStr , "https://" ) {
1046- return uploadFileHTTPPut (URLStr , file )
1054+ return uploadFileHTTPPut (ctx , URLStr , file )
10471055 }
10481056 return gcs .UploadFile (ctx , file , URLStr , publish )
10491057}
10501058
1051- func uploadFileHTTPPut (URL string , file io.Reader ) error {
1052- req , err := http .NewRequest ( http .MethodPut , URL , file )
1059+ func uploadFileHTTPPut (ctx context. Context , URL string , file io.Reader ) error {
1060+ req , err := http .NewRequestWithContext ( ctx , http .MethodPut , URL , file )
10531061 if err != nil {
10541062 return fmt .Errorf ("failed to create HTTP PUT request: %w" , err )
10551063 }
0 commit comments