Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Daylight Saving Time bugs cause failures in cookies #157

Closed
ferd opened this Issue · 4 comments

2 participants

@ferd

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

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.

@essen
Owner

Opened an issue upstream: mochi/mochiweb#73

@ghost Unknown referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this issue from a commit
Magnus Klaar Fix issue #157 relating to daylight savings time. 3376b72
@essen
Owner

Fixed in 3376b72. Thanks everyone!

@essen
Owner

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
@tsujigiri tsujigiri referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.