Skip to content

Commit

Permalink
fix file closed before complete write,.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Aug 11, 2024
1 parent 0f89a71 commit fd41807
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions telegram/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,6 @@ func (c *Client) DownloadMedia(file interface{}, Opts ...*DownloadOptions) (stri
for p := int64(0); p < parts; p++ {
wg.Add(1)
go func(p int64) {
defer wg.Done()

for {
mu.Lock()
found := false
Expand All @@ -473,13 +471,14 @@ func (c *Client) DownloadMedia(file interface{}, Opts ...*DownloadOptions) (stri
if found {
go func(i int, p int) {
defer func() {
defer wg.Done()
mu.Lock()
w[i].buzy = false
mu.Unlock()
}()

retryCount := 0
reqTimeout := 4 * time.Second
reqTimeout := 5 * time.Second

partDownloadStartPoint:
c.Logger.Debug(fmt.Sprintf("download part %d/%d in chunks of %d", p, totalParts, partSize/1024))
Expand Down Expand Up @@ -529,12 +528,11 @@ func (c *Client) DownloadMedia(file interface{}, Opts ...*DownloadOptions) (stri
}
c.Logger.Error(err)
case <-time.After(reqTimeout):
c.Logger.Debug(fmt.Errorf("upload part %d timed out - retrying", p))
retryCount++
if retryCount > 3 {
c.Logger.Debug(fmt.Errorf("upload part %d timed out - giving up", p))
if retryCount > 4 {
c.Logger.Debug(fmt.Errorf("upload part %d timed out - giving up after %d retries", p, retryCount))
return
} else if retryCount > 2 {
} else if retryCount > 3 {
reqTimeout = 6 * time.Second
}
goto partDownloadStartPoint
Expand Down

0 comments on commit fd41807

Please sign in to comment.