From e3ff3bb996a0947a1539623902cbc5701beccef3 Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Sat, 10 May 2025 17:49:00 +0200 Subject: Decrement requests in flight on clear That's a bug --- src/proto.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/proto.c b/src/proto.c index df47cbb..5d28ceb 100644 --- a/src/proto.c +++ b/src/proto.c @@ -153,6 +153,14 @@ bool alloc_req(struct dht* dht, uint16_t* reqId) { return false; } +void clear_req(struct dht *dht, uint16_t reqId) { + prom_gauge_dec(requestsInFlight, NULL); + dht->requestdata[reqId].fun = NULL; + dht->requestdata[reqId].timeout_fun = NULL; + dht->requestdata[reqId].timeout = 0; + dht->reqalloc[reqId] = false; +} + bool find_req(struct dht* dht, uint32_t transId, uint16_t* reqId) { *reqId = transId; return dht->reqalloc[transId]; @@ -731,11 +739,7 @@ int handle_packet(struct dht* dht, time_t now, enum commandType type, char* tran return 0; } - prom_gauge_inc(requestsInFlight, NULL); - dht->requestdata[reqId].fun = NULL; - dht->requestdata[reqId].timeout_fun = NULL; - dht->requestdata[reqId].timeout = 0; - dht->reqalloc[reqId] = false; + clear_req(dht, reqId); } else if(type == CT_QUERY) { // Must be a query if(transaction == NULL) fatal("No transaction in request"); @@ -881,12 +885,7 @@ int proto_run(struct dht* dht, char* buff, size_t recv_len, struct sockaddr_in* return 0; } if(rc != PROTO_EDISC) { - prom_gauge_inc(requestsInFlight, NULL); - dht->requestdata[i].fun = NULL; - dht->requestdata[i].timeout_fun = NULL; - dht->requestdata[i].timeout = 0; - dht->reqalloc[i] = false; - + clear_req(dht, i); dht->pause = false; } } -- cgit v1.2.3