From 392e380463f23981f52fbc0cae53721234984fbf Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 18 Jan 2024 23:13:14 -0500 Subject: [PATCH 1/3] set SSH timeout --- include/git2/common.h | 3 +-- src/libgit2/transports/ssh_libssh2.c | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/git2/common.h b/include/git2/common.h index ab6bc1333..7736a0af9 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -490,8 +490,7 @@ typedef enum { * * opts(GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, int timeout) * > Sets the timeout (in milliseconds) to attempt connections to - * > a remote server. This is supported only for HTTP(S) connections - * > and is not supported by SSH. Set to 0 to use the system default. + * > a remote server. Set to 0 to use the system default. * > Note that this may not be able to be configured longer than the * > system default, typically 75 seconds. * diff --git a/src/libgit2/transports/ssh_libssh2.c b/src/libgit2/transports/ssh_libssh2.c index d2be2ba33..89f341f21 100644 --- a/src/libgit2/transports/ssh_libssh2.c +++ b/src/libgit2/transports/ssh_libssh2.c @@ -23,6 +23,8 @@ #define OWNING_SUBTRANSPORT(s) ((ssh_subtransport *)(s)->parent.subtransport) +extern int git_socket_stream__connect_timeout; + static const char cmd_uploadpack[] = "git-upload-pack"; static const char cmd_receivepack[] = "git-receive-pack"; @@ -539,6 +541,10 @@ static int _git_ssh_session_create( return -1; } + if (git_socket_stream__connect_timeout > 0) { + libssh2_session_set_timeout(s, git_socket_stream__connect_timeout); + } + if ((rc = load_known_hosts(&known_hosts, s)) < 0) { ssh_error(s, "error loading known_hosts"); libssh2_session_free(s); From 7be7c0c0e01aae938f2aaf78f22f20fc1b7a7763 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 26 Jan 2024 13:37:23 -0500 Subject: [PATCH 2/3] use git_socket_stream__timeout --- include/git2/common.h | 7 +++---- src/libgit2/transports/ssh_libssh2.c | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/git2/common.h b/include/git2/common.h index 7736a0af9..140dd9561 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -490,7 +490,8 @@ typedef enum { * * opts(GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, int timeout) * > Sets the timeout (in milliseconds) to attempt connections to - * > a remote server. Set to 0 to use the system default. + * > a remote server. This is supported only for HTTP(S) connections + * > and is not supported by SSH. Set to 0 to use the system default. * > Note that this may not be able to be configured longer than the * > system default, typically 75 seconds. * @@ -500,9 +501,7 @@ typedef enum { * * opts(GIT_OPT_SET_SERVER_TIMEOUT, int timeout) * > Sets the timeout (in milliseconds) for reading from and writing - * > to a remote server. This is supported only for HTTP(S) - * > connections and is not supported by SSH. Set to 0 to use the - * > system default. + * > to a remote server. Set to 0 to use the system default. * * @param option Option key * @param ... value to set the option diff --git a/src/libgit2/transports/ssh_libssh2.c b/src/libgit2/transports/ssh_libssh2.c index 89f341f21..d1b5d40d5 100644 --- a/src/libgit2/transports/ssh_libssh2.c +++ b/src/libgit2/transports/ssh_libssh2.c @@ -23,7 +23,7 @@ #define OWNING_SUBTRANSPORT(s) ((ssh_subtransport *)(s)->parent.subtransport) -extern int git_socket_stream__connect_timeout; +extern int git_socket_stream__timeout; static const char cmd_uploadpack[] = "git-upload-pack"; static const char cmd_receivepack[] = "git-receive-pack"; @@ -541,8 +541,8 @@ static int _git_ssh_session_create( return -1; } - if (git_socket_stream__connect_timeout > 0) { - libssh2_session_set_timeout(s, git_socket_stream__connect_timeout); + if (git_socket_stream__timeout > 0) { + libssh2_session_set_timeout(s, git_socket_stream__timeout); } if ((rc = load_known_hosts(&known_hosts, s)) < 0) { From c3dc87b0c80eb4f885ba1781eed7a029c0e1e53a Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 5 Feb 2024 10:16:17 +0000 Subject: [PATCH 3/3] docs: update documentation for timeout The connect timeout *does* apply to SSH connections (at least libssh2), so update the documentation appropriately. --- include/git2/common.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/git2/common.h b/include/git2/common.h index 140dd9561..0f42c34f6 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -490,10 +490,9 @@ typedef enum { * * opts(GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, int timeout) * > Sets the timeout (in milliseconds) to attempt connections to - * > a remote server. This is supported only for HTTP(S) connections - * > and is not supported by SSH. Set to 0 to use the system default. - * > Note that this may not be able to be configured longer than the - * > system default, typically 75 seconds. + * > a remote server. Set to 0 to use the system default. Note that + * > this may not be able to be configured longer than the system + * > default, typically 75 seconds. * * opts(GIT_OPT_GET_SERVER_TIMEOUT, int *timeout) * > Gets the timeout (in milliseconds) for reading from and writing