Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 86d0a53

Browse files
rnowosielskiRafal Nowosielski
authored andcommitted
Set timeout on remote (WinHTTP) should return error in case of failure. Connection timeout set to 1 minute. Read/Write timeout remains set to infinite libgit2#2147
1 parent 2db7119 commit 86d0a53

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/transports/winhttp.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
#define WINHTTP_OPTION_PEERDIST_EXTENSION_STATE 109
3636
#define CACHED_POST_BODY_BUF_SIZE 4096
3737
#define UUID_LENGTH_CCH 32
38-
38+
#define TIMEOUT_INFINITE -1
39+
#define DEFAULT_CONNECT_TIMEOUT 60000
3940
#ifndef WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH
4041
#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0
4142
#endif
@@ -212,8 +213,8 @@ static int winhttp_stream_connect(winhttp_stream *s)
212213
BOOL peerdist = FALSE;
213214
int error = -1;
214215
unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS;
215-
int default_timeout = -1;
216-
216+
int default_timeout = TIMEOUT_INFINITE;
217+
int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
217218

218219
/* Prepare URL */
219220
git_buf_printf(&buf, "%s%s", t->connection_data.path, s->service_url);
@@ -242,8 +243,11 @@ static int winhttp_stream_connect(winhttp_stream *s)
242243
goto on_error;
243244
}
244245

245-
WinHttpSetTimeouts(s->request, default_timeout, default_timeout, default_timeout, default_timeout);
246-
246+
if (!WinHttpSetTimeouts(s->request, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
247+
giterr_set(GITERR_OS, "Failed to set timeouts for WinHTTP");
248+
goto on_error;
249+
}
250+
247251
/* Set proxy if necessary */
248252
if (git_remote__get_http_proxy(t->owner->owner, !!t->connection_data.use_ssl, &proxy_url) < 0)
249253
goto on_error;
@@ -471,7 +475,8 @@ static int winhttp_connect(
471475
int32_t port;
472476
const char *default_port = "80";
473477
int error = -1;
474-
int default_timeout = -1;
478+
int default_timeout = TIMEOUT_INFINITE;
479+
int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
475480

476481
/* Prepare port */
477482
if (git__strtol32(&port, t->connection_data.port, NULL, 10) < 0)
@@ -496,7 +501,10 @@ static int winhttp_connect(
496501
goto on_error;
497502
}
498503

499-
WinHttpSetTimeouts(t->session, default_timeout, default_timeout, default_timeout, default_timeout);
504+
if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
505+
giterr_set(GITERR_OS, "Failed to set timeouts for WinHTTP");
506+
goto on_error;
507+
}
500508

501509

502510
/* Establish connection */

0 commit comments

Comments
 (0)