Skip to content

Commit

Permalink
Temp fix for http pool and disable Expired check
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzy823 committed Jan 15, 2024
1 parent a633e19 commit cbd1a17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/auth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import experimental/parser/guestaccount

# max requests at a time per account to avoid race conditions
const
maxConcurrentReqs = 2
maxConcurrentReqs = 5
dayInSeconds = 24 * 60 * 60
apiMaxReqs: Table[Api, int] = {
Api.search: 50,
Expand Down Expand Up @@ -203,7 +203,7 @@ proc initAccountPool*(cfg: Config; path: string) =
quit 1

let accountsPrePurge = accountPool.len
accountPool.keepItIf(not it.hasExpired)
#accountPool.keepItIf(not it.hasExpired)

log "Successfully added ", accountPool.len, " valid accounts."
if accountsPrePurge > accountPool.len:
Expand Down
7 changes: 7 additions & 0 deletions src/http_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ proc setHttpProxy*(url: string; auth: string) =
else:
proxy = nil

proc clear*(pool: HttpPool) =
for client in pool.conns:
try: client.close()
except: discard
pool.conns.setLen(0)

proc release*(pool: HttpPool; client: AsyncHttpClient; badClient=false) =
if pool.conns.len >= maxConns or badClient:
try: client.close()
Expand All @@ -42,6 +48,7 @@ template use*(pool: HttpPool; heads: HttpHeaders; body: untyped): untyped =
except BadClientError, ProtocolError:
# Twitter returned 503 or closed the connection, we need a new client
pool.release(c, true)
pool.clear()
badClient = false
c = pool.acquire(heads)
body
Expand Down

0 comments on commit cbd1a17

Please sign in to comment.