Skip to content

Commit

Permalink
curl: fix --upload-file . hangs if delay in STDIN
Browse files Browse the repository at this point in the history
Attempt to unpause a busy read in the CURLOPT_XFERINFOFUNCTION.

When uploading from stdin in non-blocking mode, a delay in reading
the stream (EAGAIN) causes curl to pause sending data
(CURL_READFUNC_PAUSE).  Prior to this change, a busy read was
detected and unpaused only in the CURLOPT_WRITEFUNCTION handler.
This change performs the same busy read handling in a
CURLOPT_XFERINFOFUNCTION handler.

Fixes: curl#2051
Reported-by: @bdry
  • Loading branch information
jpschroeder committed Nov 15, 2019
1 parent c6b70de commit dd6e15c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/tool_cb_rea.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "tool_cfgable.h"
#include "tool_cb_rea.h"
#include "tool_operate.h"

#include "memdebug.h" /* keep this as LAST include */

Expand All @@ -52,3 +53,28 @@ size_t tool_read_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
in->config->readbusy = FALSE;
return (size_t)rc;
}

/*
** callback for CURLOPT_XFERINFOFUNCTION used to unpause busy reads
*/

int tool_readbusy_cb(void *clientp,
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow)
{
struct per_transfer *per = clientp;
struct OutStruct *outs = &per->outs;
struct OperationConfig *config = outs->config;

(void)dltotal; /* unused */
(void)dlnow; /* unused */
(void)ultotal; /* unused */
(void)ulnow; /* unused */

if(config->readbusy) {
config->readbusy = FALSE;
curl_easy_pause(per->curl, CURLPAUSE_CONT);
}

return 0;
}
8 changes: 8 additions & 0 deletions src/tool_cb_rea.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@

size_t tool_read_cb(void *buffer, size_t sz, size_t nmemb, void *userdata);

/*
** callback for CURLOPT_XFERINFOFUNCTION used to unpause busy reads
*/

int tool_readbusy_cb(void *clientp,
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow);

#endif /* HEADER_CURL_TOOL_CB_REA_H */
12 changes: 12 additions & 0 deletions src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,12 @@ static CURLcode single_transfer(struct GlobalConfig *global,
global->isatty = orig_isatty;
}

if(per->uploadfile && !strcmp(per->uploadfile, ".")) {
/* when reading from stdin in non-blocking mode, we use the progress
function to unpause a busy read */
global->noprogress = FALSE;
}

if(urlnum > 1 && !global->mute) {
per->separator_err =
aprintf("\n[%lu/%lu]: %s --> %s",
Expand Down Expand Up @@ -1575,6 +1581,12 @@ static CURLcode single_transfer(struct GlobalConfig *global,
my_setopt(curl, CURLOPT_XFERINFOFUNCTION, tool_progress_cb);
my_setopt(curl, CURLOPT_XFERINFODATA, &per->progressbar);
}
else if(per->uploadfile && !strcmp(per->uploadfile, ".")) {
/* when reading from stdin in non-blocking mode, we use the progress
function to unpause a busy read */
my_setopt(curl, CURLOPT_XFERINFOFUNCTION, tool_readbusy_cb);
my_setopt(curl, CURLOPT_XFERINFODATA, per);
}

/* new in libcurl 7.24.0: */
if(config->dns_servers)
Expand Down

0 comments on commit dd6e15c

Please sign in to comment.