extend/cowboy — Issue #157: Daylight Saving Time bugs cause failures in cookies
Author: ferd
Created: 2012-03-09 14:19:20+00:00
State: open

Although I'm not quite sure what countries (if any) change their DST today (March 9 at ~2-3 am EST, 2012), we've had a sequence of crashes related to the cookie handling in cowboy failing:

2012-03-09 02:54:34.013 [error] <0.29836.839> ** Handler rtb_handler terminating in handle/2 for the reason error:{case_clause,[]}
1158 ** Options were {...}
1159 ** Handler state was {state,{config,cassanderl_dispatch,800,ets,36893,40990}}
1160 ** Request was {http_req,#Port<0.39651388>,cowboy_tcp_transport,keepalive,'GET',{1,1},undefined,[...],undefined,<<"..."> >,80,
[...],undefined,<<"...">>,undefined,<<"...">>,[],[{'Connection',<<"keep-alive">>},{'Accept-Encoding',<<"gzip, deflate">>},
{'Accept-Language',<<"en-us">>},{'Referer',<<"...">>},{'Accept',<<"*/*">>},
{'User-Agent',<<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7">>},
{'Host',<<"...">>}],undefined,waiting,<<>>,locked}
1161 ** Stacktrace: [{cowboy_clock,rfc2109,1},{cowboy_cookies,cookie,3},...,{cowboy_http_protocol,handler_loop,3}]

The exception seems to come from a bad handling of the possible return values from `calendar:local_time_to_universal_time_dst/1` where the documentation says:

> []
>
> For a local {Date1, Time1} during the period that is skipped when switching to daylight saving time, there is no corresponding UTC since the local time is illegal - it has never happened.

This `[]` return value isn't handled in cowboy_clock in this part of the code:

rfc2109(LocalTime) ->
{{YYYY,MM,DD},{Hour,Min,Sec}} =
case calendar:local_time_to_universal_time_dst(LocalTime) of
[Gmt] -> Gmt;
[_,Gmt] -> Gmt
end,
...

Which provokes crashes.