@@ -45,10 +45,18 @@ sub disconnect {
45
45
sub _connect {
46
46
my ($self ) = @_ ;
47
47
48
+ # We don't need to retry too early if an attempt failed recently
49
+ if ($self -> {_ssh2_dont_retry_before }) {
50
+ return 0 if time < $self -> {_ssh2_dont_retry_before };
51
+ delete $self -> {_ssh2_dont_retry_before };
52
+ }
53
+
48
54
unless ($self -> {_ssh2 } || ($self -> mode(' ssh' ) && !$self -> mode(' libssh2' ))) {
49
55
Net::SSH2-> require();
50
56
if ($EVAL_ERROR ) {
51
57
$self -> {logger }-> debug(" Can't use libssh2: $EVAL_ERROR " );
58
+ # Don't retry to load libssh2 before a minute
59
+ $self -> {_ssh2_dont_retry_before } = time + 60;
52
60
} else {
53
61
my $timeout = $self -> timeout();
54
62
$self -> {_ssh2 } = Net::SSH2-> new(timeout => $timeout * 1000);
@@ -70,7 +78,9 @@ sub _connect {
70
78
my @error = $ssh2 -> error;
71
79
$self -> {logger }-> debug(" Can't reach $remote for ssh remoteinventory via libssh2: @error " );
72
80
undef $self -> {_ssh2 };
73
- return ;
81
+ # Don't retry to connect with libssh2 before a minute
82
+ $self -> {_ssh2_dont_retry_before } = time + 60;
83
+ return 0;
74
84
}
75
85
76
86
# Use Trust On First Use policy to verify remote host
@@ -103,9 +113,11 @@ sub _connect {
103
113
}
104
114
unless ($ssh2 -> check_hostkey($hostkey_checking )) {
105
115
my @error = $ssh2 -> error;
106
- $self -> {logger }-> error(" Can't trust $remote for ssh remoteinventory: @error " );
116
+ $self -> {logger }-> error(" [libssh2] Can't trust $remote for ssh remoteinventory: @error " );
107
117
undef $self -> {_ssh2 };
108
- return ;
118
+ # Don't retry to connect with libssh2 before a minute
119
+ $self -> {_ssh2_dont_retry_before } = time + 60;
120
+ return 0;
109
121
}
110
122
111
123
# Support authentication by password
@@ -161,8 +173,12 @@ sub _connect {
161
173
}
162
174
}
163
175
164
- $self -> {logger }-> error(" Can't authenticate on $remote remote host" );
176
+ $self -> {logger }-> error(" Can't authenticate on $remote remote host via libssh2 " );
165
177
undef $self -> {_ssh2 };
178
+
179
+ # Don't retry libssh2 before a minute
180
+ $self -> {_ssh2_dont_retry_before } = time + 60;
181
+
166
182
return 0;
167
183
}
168
184
0 commit comments