The Watchdog Hydra

This post was originally published on this site

The Daily WTF

Ammar A uses Node to consume an HTTP API. The API uses cookies to track session information, and ensures those cookies expire, so clients need to periodically re-authenticate. How frequently?

That’s an excellent question, and one that neither Ammar nor the docs for this API can answer. The documentation provides all the clarity and consistency of a religious document, which is to say you need to take it on faith that these seemingly random expirations happen for a good reason.

Ammar, not feeling particularly faithful, wrote a little “watchdog” function. Once you log in, every thirty seconds it tries to fetch a URL, hopefully keeping the session alive, or, if it times out, starts a new session.

That’s what it was supposed to do, but Ammar made a mistake.

function login(cb) { request.post({url: ‘/login’, form:{username: config.username, password: config.password}, function(err, response) { if (err) return cb(err) if (response.statusCode !=

To read the full article click on the 'post' link at the top.