diff --git a/cmd/downloader/downloader/grpc_server.go b/cmd/downloader/downloader/grpc_server.go index 5bca2bafe87..c841e565771 100644 --- a/cmd/downloader/downloader/grpc_server.go +++ b/cmd/downloader/downloader/grpc_server.go @@ -77,9 +77,19 @@ func (s *GrpcServer) Download(ctx context.Context, request *proto_downloader.Dow } if _, ok := s.t.TorrentClient.Torrent(infoHashes[i]); !ok { magnet := mi.Magnet(&infoHashes[i], nil) - if _, err := s.t.TorrentClient.AddMagnet(magnet.String()); err != nil { + t, err := s.t.TorrentClient.AddMagnet(magnet.String()) + if err != nil { return nil, err } + select { + case <-ctx.Done(): + return nil, ctx.Err() + case <-t.GotInfo(): + metaInfo := t.Metainfo() + if err := CreateTorrentFileIfNotExists(s.snapshotDir, t.Info(), &metaInfo); err != nil { + return nil, err + } + } } } if len(infoHashes) == 1 { @@ -87,15 +97,6 @@ func (s *GrpcServer) Download(ctx context.Context, request *proto_downloader.Dow if !ok { return nil, fmt.Errorf("torrent not found: [%x]", infoHashes[0]) } - select { - case <-ctx.Done(): - return nil, ctx.Err() - case <-t.GotInfo(): - metaInfo := t.Metainfo() - if err := CreateTorrentFileIfNotExists(s.snapshotDir, t.Info(), &metaInfo); err != nil { - return nil, err - } - } t.AllowDataUpload() t.AllowDataDownload() if !t.Complete.Bool() {