aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Kovalev <[email protected]>2015-03-26 11:15:05 +0300
committerAlex Kovalev <[email protected]>2015-03-26 11:15:05 +0300
commitc05143aba82a36c7a063a0895a7c32be52d165aa (patch)
tree061a1472a376c50f3f92354b5474a30fecc99651
parent3d9078018d7f0a83a359b70c698d35e35fbb94f9 (diff)
downloadcowboy-c05143aba82a36c7a063a0895a7c32be52d165aa.tar.gz
cowboy-c05143aba82a36c7a063a0895a7c32be52d165aa.tar.bz2
cowboy-c05143aba82a36c7a063a0895a7c32be52d165aa.zip
fixed cowboy_clock inbox overflow if system clock was changed
-rw-r--r--src/cowboy_clock.erl6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/cowboy_clock.erl b/src/cowboy_clock.erl
index 37767e1..66fd5d4 100644
--- a/src/cowboy_clock.erl
+++ b/src/cowboy_clock.erl
@@ -65,7 +65,7 @@ init([]) ->
named_table, {read_concurrency, true}]),
T = erlang:universaltime(),
B = update_rfc1123(<<>>, undefined, T),
- {ok, TRef} = timer:send_interval(1000, update),
+ TRef = erlang:send_after(1000, self(), update),
ets:insert(?MODULE, {rfc1123, B}),
{ok, #state{universaltime=T, rfc1123=B, tref=TRef}}.
@@ -83,10 +83,12 @@ handle_cast(_Msg, State) ->
{noreply, State}.
-spec handle_info(any(), State) -> {noreply, State} when State::#state{}.
-handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) ->
+handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef0}) ->
+ erlang:cancel_timer(TRef0),
T = erlang:universaltime(),
B2 = update_rfc1123(B1, Prev, T),
ets:insert(?MODULE, {rfc1123, B2}),
+ TRef = erlang:send_after(1000, self(), update),
{noreply, #state{universaltime=T, rfc1123=B2, tref=TRef}};
handle_info(_Info, State) ->
{noreply, State}.