enforce max_payload_size code can lead to infinite loop when payload is full of custom fields, and can't reduce anymore alert body.
Proposed Solution:
die with error instead of eating all CPU for ever.
Locate "# enforce max_payload_size" on _pack_payload_for_devicetoken,
change the code to something like this:
# enforce max_payload_size
my $max_payload_size = $self->max_payload_size;
if ( bytes::length($json) > $max_payload_size ) {
# not sure why this is necessary. Must be something
# about the difference in density b/n utf8 and unicode?
# This isn't very efficient,
# but users shouldn't be passing in huge strings, surely...
my $too_big = 0;
while ( bytes::length($json) > $max_payload_size ) {
eval {
_apply_to_alert_body(
$payload,
sub {
my $text = substr( $_[0], 0, -1 );
$too_big = 1 if length $text < 1;
return $text;
}
);
};
$json = JSON::XS::encode_json($payload);
die sprintf "Payload [%s] is bigger than max_payload_size [%s]!\n", bytes::length($json), $max_payload_size
if $too_big;
die $@ if $@;
}
}
Thanks you for the module!