Skip to content

Commit 221f624

Browse files
authored
Increase metadata fetch timeout to 30s (#803)
Signed-off-by: Wayne Zhang <qiwzhang@google.com>
1 parent 816a204 commit 221f624

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

‎src/api_manager/fetch_metadata.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ const char kMetadataInstanceIdentityToken[] =
4242
const int kInstanceIdentityTokenExpiration = 3500;
4343
// Time window (in seconds) of failure status after a failed fetch.
4444
const int kFailureStatusWindow = 5;
45-
// GKE metadata server may take >2s to fetch access token.
46-
// Initial metadata fetch timeout (5s)
47-
const int kMetadataFetchTimeout = 5000;
45+
// GKE metadata server may take >20s to fetch access token (b/148454048).
46+
// Initial metadata fetch timeout (30s)
47+
const int kMetadataFetchTimeout = 30000;
4848
// Maximum number of retries to fetch token from metadata
4949
const int kMetadataTokenFetchRetries = 3;
5050
// External status message for failure to fetch service account token

‎src/nginx/t/ApiManager.pm

+8-4
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ sub http($;$;%) {
580580
my $s = http_start($port, $request, %extra);
581581

582582
return $s if $extra{start} or !defined $s;
583-
return http_end($s);
583+
return http_end($s, %extra);
584584
}
585585

586586
sub http_start($;$;%) {
@@ -590,7 +590,9 @@ sub http_start($;$;%) {
590590
eval {
591591
local $SIG{ALRM} = sub { die "timeout\n" };
592592
local $SIG{PIPE} = sub { die "sigpipe\n" };
593-
alarm(8);
593+
my $timeout = 8;
594+
$timeout = $extra{timeout} if $extra{timeout};
595+
alarm($timeout);
594596

595597
$s = $extra{socket} || IO::Socket::INET->new(
596598
Proto => 'tcp',
@@ -621,13 +623,15 @@ sub http_start($;$;%) {
621623
}
622624

623625
sub http_end($;%) {
624-
my ($s) = @_;
626+
my ($s, %extra) = @_;
625627
my $reply;
626628

627629
eval {
628630
local $SIG{ALRM} = sub { die "timeout\n" };
629631
local $SIG{PIPE} = sub { die "sigpipe\n" };
630-
alarm(8);
632+
my $timeout = 8;
633+
$timeout = $extra{timeout} if $extra{timeout};
634+
alarm($timeout);
631635

632636
local $/;
633637
$reply = $s->getline();

‎src/nginx/t/metadata_timeout.t

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ $t->run();
9696

9797
################################################################################
9898

99-
my $shelves = ApiManager::http_get($NginxPort,'/shelves');
99+
my $shelves = ApiManager::http_get($NginxPort,'/shelves', (timeout => 40));
100100
my $books = ApiManager::http_get($NginxPort,'/shelves/Musicals/books');
101101

102102
is($t->waitforfile("$t->{_testdir}/${report_done}"), 1, 'Report body file ready.');
@@ -207,8 +207,8 @@ sub metadata {
207207

208208
$request_count++;
209209
if ($request_count == 1) {
210-
# Trigger a timeout for the first request.
211-
sleep 7;
210+
# Trigger a timeout for the first request. timeout is 30s.
211+
sleep 32;
212212
}
213213

214214
print $client <<'EOF';

‎start_esp/fetch_service_config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def fetch_metadata(metadata, attr_path, required):
6060
headers = {"Metadata-Flavor": "Google"}
6161
client = urllib3.PoolManager(ca_certs=certifi.where())
6262
if required:
63-
timeout = 1.0
63+
# GKE metadata server may take up to 30s to get access token.
64+
timeout = 30.0
6465
retries = True
6566
else:
6667
timeout = 0.1

0 commit comments

Comments
 (0)