diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2025-05-10 17:49:00 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2025-05-10 17:49:00 +0200 |
| commit | e3ff3bb996a0947a1539623902cbc5701beccef3 (patch) | |
| tree | fe23a294391f8f1e9729a7968a7fc9d38a79267a | |
| parent | 89ef4c5c3bdc65862bffcffb7e9e21103d4e8bb4 (diff) | |
Decrement requests in flight on clear
That's a bug
| -rw-r--r-- | src/proto.c | 21 |
1 files changed, 10 insertions, 11 deletions
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; } } |
