Skip to content

Commit

Permalink
Merge pull request #16140 from mlschroe/master
Browse files Browse the repository at this point in the history
[backend] BSNotify: do not use chunked encoding for the payload
  • Loading branch information
mlschroe committed May 15, 2024
2 parents 005d398 + 672f335 commit d27a65c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
11 changes: 5 additions & 6 deletions src/backend/BSNotify.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@ sub notify {
# strip
$p = { map {$_ => $p->{$_}} grep {defined($p->{$_}) && !ref($p->{$_})} sort keys %{$p || {}} };

my $timeout = 60;
$timeout += int(length($$payloadref) / 500000) if $payloadref;
$timeout = 3600 if $timeout > 3600;
my $param = {
'uri' => "$BSConfig::srcserver/notify/$type",
'request' => 'POST',
'formurlencode' => 1,
'timeout' => $timeout,
'timeout' => 60,
};
if ($payloadref) {
$param->{'headers'} = [ 'Content-Type: application/octet-stream' ];
$param->{'chunked'} = 1;
my $payloadsize = length($$payloadref);
my $timeout = 60 + int($payloadsize / 500000);
$param->{'timeout'} = $timeout > 3600 ? 3600 : $timeout;
$param->{'headers'} = [ 'Content-Type: application/octet-stream', "Content-Length: $payloadsize" ];
$param->{'data'} = $payloadref;
$param->{'datafmt'} = \&payload_datafmt;
$param->{'formurlencode'} = 0;
Expand Down
22 changes: 9 additions & 13 deletions src/backend/BSUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,7 @@ sub retrieve {
eval {
$dd = ref($fn) ? Storable::fd_retrieve($fn) : Storable::retrieve($fn);
};
if (!$dd && $nonfatal == 2) {
if ($@) {
warn($@);
} else {
warn("retrieve $fn: $!\n");
}
}
warn($@ || "retrieve $fn: $!\n") if !$dd && $nonfatal == 2;
}
return $dd;
}
Expand All @@ -607,13 +601,15 @@ sub tostorable {

sub fromstorable {
my $nonfatal = $_[1];
return Storable::thaw(substr($_[0], 4)) unless $nonfatal;
my $d = eval { Storable::thaw(substr($_[0], 4)) };
if ($@) {
warn($@) if $nonfatal == 2;
return undef;
my $dd;
if (!$nonfatal) {
$dd = Storable::thaw(substr($_[0], 4));
die("fromstorable error\n") unless $dd;
} else {
$dd = eval { Storable::thaw(substr($_[0], 4)) };
warn($@ || "fromstorable error\n") if !$dd && $nonfatal == 2;
}
return $d;
return $dd;
}

sub ping {
Expand Down

0 comments on commit d27a65c

Please sign in to comment.