Skip to content

Commit

Permalink
Fix? leak when retrying to scrape embed
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Aug 14, 2024
1 parent d6a1e88 commit a06d828
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions handlers/scraper/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,24 @@ func (i *InstaData) ScrapeData() error {

var body []byte
for retries := 0; retries < 3; retries++ {
res, err := client.Do(req)
if res != nil && res.StatusCode == 200 {
err := func() error {
res, err := client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return errors.New("status code is not 200")
}

body, err = io.ReadAll(res.Body)
if err == nil && len(body) > 0 {
break
if err != nil {
return err
}
return nil
}()
if err == nil {
break
}
}

Expand Down

0 comments on commit a06d828

Please sign in to comment.