Skip to content

Commit

Permalink
ama
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Jan 29, 2025
1 parent 73f8bfa commit 2538a53
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions handlers/scraper/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"log/slog"
"net"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -37,7 +36,6 @@ func InitRemoteScraper(listenAddr *net.TCPAddr, authCode []byte) error {
for {
conn, err := ln.Accept()
if err != nil {
conn.Close()
continue
}

Expand All @@ -59,26 +57,21 @@ func InitRemoteScraper(listenAddr *net.TCPAddr, authCode []byte) error {
}

func handleConnection(conn net.Conn) {
var wg sync.WaitGroup

defer func() {
sessCount.Add(-1)
conn.Close()
wg.Done()
}()
sessCount.Add(1)
wg.Add(1)

for rm := range inChan {
var err error
if err := conn.SetDeadline(time.Now().Add(5 * time.Second)); err != nil {
slog.Error("failed to set deadline", "err", err)
rm.outChan <- err
return
}

buf := []byte(rm.instaData.PostID)
if _, err = conn.Write(buf); err != nil {
if _, err := conn.Write(buf); err != nil {
slog.Error("failed to write to stream", "err", err)
rm.outChan <- err
return
Expand All @@ -92,7 +85,7 @@ func handleConnection(conn net.Conn) {
return
}

if err = binary.Unmarshal(outBuf[:n], rm.instaData); err != nil {
if err := binary.Unmarshal(outBuf[:n], rm.instaData); err != nil {
slog.Error("failed to unmarshal data", "err", err)
rm.outChan <- err
continue
Expand All @@ -104,8 +97,6 @@ func handleConnection(conn net.Conn) {
}
rm.outChan <- nil
}

wg.Wait()
}

func ScrapeRemote(i *InstaData) error {
Expand Down

0 comments on commit 2538a53

Please sign in to comment.