Skip to content

Commit 9dd85bc

Browse files
committed
multi: progress function abort must close connection
When the progress function returns to cancel the request, we must mark the connection to get closed and it must do to the DONE state. do_init() must be called as early as possible so that state variables for new connections are reset early. We could otherwise see that the old values were still there when a connection was to be disconnected very early and it would make it behave wrongly. Bug: http://curl.haxx.se/mail/lib-2011-10/0006.html Reported by: Vladimir Grishchenko
1 parent 5d45285 commit 9dd85bc

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/multi.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,8 +1657,14 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
16571657
}
16581658
/* if there's still a connection to use, call the progress function */
16591659
else if(easy->easy_conn && Curl_pgrsUpdate(easy->easy_conn)) {
1660-
easy->result = CURLE_ABORTED_BY_CALLBACK;
1661-
multistate(easy, CURLM_STATE_COMPLETED);
1660+
/* aborted due to progress callback return code must close the
1661+
connection */
1662+
easy->easy_conn->bits.close = TRUE;
1663+
1664+
/* if not yet in DONE state, go there, otherwise COMPLETED */
1665+
multistate(easy, (easy->state < CURLM_STATE_DONE)?
1666+
CURLM_STATE_DONE: CURLM_STATE_COMPLETED);
1667+
result = CURLM_CALL_MULTI_PERFORM;
16621668
}
16631669
}
16641670
} WHILE_FALSE; /* just to break out from! */

lib/url.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ int curl_win32_idn_to_ascii(const char *in, char **out);
136136
static long ConnectionKillOne(struct SessionHandle *data);
137137
static void conn_free(struct connectdata *conn);
138138
static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke);
139+
static CURLcode do_init(struct connectdata *conn);
139140

140141
/*
141142
* Protocol table.
@@ -4988,6 +4989,9 @@ static CURLcode create_conn(struct SessionHandle *data,
49884989
ConnectionStore(data, conn);
49894990
}
49904991

4992+
/* Setup and init stuff before DO starts, in preparing for the transfer. */
4993+
do_init(conn);
4994+
49914995
/*
49924996
* Setup whatever necessary for a resumed transfer
49934997
*/
@@ -5334,9 +5338,6 @@ CURLcode Curl_do(struct connectdata **connp, bool *done)
53345338
struct connectdata *conn = *connp;
53355339
struct SessionHandle *data = conn->data;
53365340

5337-
/* setup and init stuff before DO starts, in preparing for the transfer */
5338-
do_init(conn);
5339-
53405341
if(conn->handler->do_it) {
53415342
/* generic protocol-specific function pointer set in curl_connect() */
53425343
result = conn->handler->do_it(conn, done);

0 commit comments

Comments
 (0)