Skip to content

Commit f4691cf

Browse files
authored
Merge pull request #90 from wolfpack9377/negative-timer-send-after
Make sure the update callback timeout is valid - erlang:send_after crashes if provided a negative value
2 parents f324210 + d7498b3 commit f4691cf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/aws_credentials.erl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,15 @@ setup_update_callback(Expires) when is_binary(Expires) ->
221221
setup_update_callback(Expires) when is_integer(Expires) ->
222222
setup_callback(Expires - ?ALERT_BEFORE_EXPIRY).
223223

224-
-spec setup_callback(pos_integer()) -> reference().
224+
-spec setup_callback(integer()) -> reference().
225225
setup_callback(Seconds) ->
226-
erlang:send_after(Seconds * 1000, self(), refresh_credentials).
226+
erlang:send_after(timeout(Seconds) * 1000, self(), refresh_credentials).
227+
228+
-spec timeout(integer()) -> pos_integer().
229+
timeout(Seconds) when is_integer(Seconds), Seconds >= 0 ->
230+
Seconds;
231+
timeout(_) ->
232+
?RETRY_DELAY.
227233

228234
-spec seconds_until_timestamp(binary()) -> integer().
229235
seconds_until_timestamp(Timestamp) ->

0 commit comments

Comments
 (0)