Skip to content

Commit 53f3138

Browse files
distorted-mdwJunio C Hamano
authored andcommitted
http-fetch: Abort requests for objects which arrived in packs
In fetch_object, there's a call to release an object request if the object mysteriously arrived, say in a pack. Unfortunately, the fetch attempt for this object might already be in progress, and we'll leak the descriptor. Instead, try to tidy away the request. Signed-off-by: Mark Wooding <mdw@distorted.org.uk> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 66f04f3 commit 53f3138

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

http-fetch.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,20 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
773773
return 0;
774774
}
775775

776+
static void abort_object_request(struct object_request *obj_req)
777+
{
778+
if (obj_req->local >= 0) {
779+
close(obj_req->local);
780+
obj_req->local = -1;
781+
}
782+
unlink(obj_req->tmpfile);
783+
if (obj_req->slot) {
784+
release_active_slot(obj_req->slot);
785+
obj_req->slot = NULL;
786+
}
787+
release_object_request(obj_req);
788+
}
789+
776790
static int fetch_object(struct alt_base *repo, unsigned char *sha1)
777791
{
778792
char *hex = sha1_to_hex(sha1);
@@ -785,7 +799,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
785799
return error("Couldn't find request for %s in the queue", hex);
786800

787801
if (has_sha1_file(obj_req->sha1)) {
788-
release_object_request(obj_req);
802+
abort_object_request(obj_req);
789803
return 0;
790804
}
791805

http.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,26 @@ void run_active_slot(struct active_request_slot *slot)
420420
#endif
421421
}
422422

423-
static void finish_active_slot(struct active_request_slot *slot)
423+
static void closedown_active_slot(struct active_request_slot *slot)
424424
{
425425
active_requests--;
426426
slot->in_use = 0;
427+
}
428+
429+
void release_active_slot(struct active_request_slot *slot)
430+
{
431+
closedown_active_slot(slot);
432+
if (slot->curl) {
433+
curl_multi_remove_handle(curlm, slot->curl);
434+
curl_easy_cleanup(slot->curl);
435+
slot->curl = NULL;
436+
}
437+
fill_active_slots();
438+
}
439+
440+
static void finish_active_slot(struct active_request_slot *slot)
441+
{
442+
closedown_active_slot(slot);
427443
curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
428444

429445
/* Store slot results so they can be read after the slot is reused */

http.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extern struct active_request_slot *get_active_slot(void);
6161
extern int start_active_slot(struct active_request_slot *slot);
6262
extern void run_active_slot(struct active_request_slot *slot);
6363
extern void finish_all_active_slots(void);
64+
extern void release_active_slot(struct active_request_slot *slot);
6465

6566
#ifdef USE_CURL_MULTI
6667
extern void fill_active_slots(void);

0 commit comments

Comments
 (0)