mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-07-05 16:59:57 +00:00
fix(dht-proxy): read timeout to prevent slot exhaustion (#1484)
Signed-off-by: Chrysostomos Nanakos <chris@include.gr>
This commit is contained in:
parent
d94417a221
commit
b5ac492fac
@ -61,6 +61,18 @@ proc handleLookupRequest(
|
||||
self: DhtProxyProtocol, conn: Connection
|
||||
) {.async: (raises: [CancelledError]).} =
|
||||
try:
|
||||
let reqBytes =
|
||||
try:
|
||||
await conn.readLp(MaxLookupRequestBytes).wait(DhtProxyRequestReadTimeout)
|
||||
except AsyncTimeoutError:
|
||||
debug "DHT proxy request read timed out"
|
||||
return
|
||||
|
||||
let req = LookupRequest.decode(reqBytes).valueOr:
|
||||
warn "Failed to decode lookup request"
|
||||
await conn.writeLp(LookupResponse(code: LookupCode.ErrDecodeFailed).encode())
|
||||
return
|
||||
|
||||
if self.inFlight >= self.maxInFlight:
|
||||
debug "DHT proxy at capacity, replying ErrTooBusy",
|
||||
inFlight = self.inFlight, max = self.maxInFlight
|
||||
@ -71,13 +83,6 @@ proc handleLookupRequest(
|
||||
defer:
|
||||
dec self.inFlight
|
||||
|
||||
let
|
||||
reqBytes = await conn.readLp(MaxLookupRequestBytes)
|
||||
req = LookupRequest.decode(reqBytes).valueOr:
|
||||
warn "Failed to decode lookup request"
|
||||
await conn.writeLp(LookupResponse(code: LookupCode.ErrDecodeFailed).encode())
|
||||
return
|
||||
|
||||
let resp =
|
||||
case req.queryType
|
||||
of FindProviders:
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import pkg/chronos
|
||||
import pkg/libp2p/protobuf/minprotobuf
|
||||
import pkg/libp2p_mix
|
||||
import pkg/libp2p/routing_record
|
||||
@ -19,6 +20,7 @@ import ../logutils
|
||||
const DhtProxyCodec* = "/storage/dht-proxy/1.0.0"
|
||||
|
||||
const DefaultMaxInFlightLookups* = 100
|
||||
const DhtProxyRequestReadTimeout* = 5.seconds
|
||||
|
||||
let MaxLookupRequestBytes* = getMaxMessageSizeForCodec(DhtProxyCodec, 1).expect(
|
||||
"DhtProxyCodec framing leaves no room for a Sphinx forward payload"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user