Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Daylight Saving Time bugs cause failures in cookies #157

Closed
ferd opened this Issue Mar 9, 2012 · 4 comments

Comments

Projects
None yet
2 participants
Contributor

ferd commented Mar 9, 2012

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.

@ghost

ghost commented Mar 9, 2012

Thanks for the hard work of narrowing down the list of suspects. The root cause of the error was that the cowboy_cookies module generates localtimes that doesn't exist when it creates the expiration time for the cookie. In this case the date was 2012-03-09, the max_age used for the cookie was two days and the daylight savings time in Canada starts at 2012-03-11.

Owner

essen commented Mar 9, 2012

Opened an issue upstream: mochi/mochiweb#73

Owner

essen commented Mar 9, 2012

Fixed in 3376b72. Thanks everyone!

Owner

essen commented Mar 9, 2012

I'll make sure we only deal with universal time when reworking the cookies code, so this shouldn't be an issue at all anymore at some point.

@essen essen closed this Mar 9, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment