herokutwitterplayframeworksecuresocial

SecureSocial login issues on Heroku with # of dynos > 1


I have Play 2.2 application which is deployed on Heroku. It works absolutely fine when I have only 1 dyno. If I add at least one more dyno, very annoying issue appears: randomly, from time to time login with Twitter or Facebook fail.

I checked the logs and it looks like the problem is with double request from Twitter.

2014-11-21T16:46:54.880238+00:00 heroku[router]: at=info method=GET path="/authenticate/twitter" host=teller.happymelly.com request_id=2c9e9ce7-8055-491d-841a-919a560461ef fwd="95.28.27.42" dyno=web.1 connect=1ms service=299ms status=303 bytes=398
2014-11-21T16:46:56.245743+00:00 heroku[router]: at=info method=GET path="/authenticate/twitter?oauth_token=XXXX&oauth_verifier=XXXX" host=teller.happymelly.com request_id=fc7966a3-082f-418b-a424-ff4868cbf175 fwd="95.28.27.42" dyno=web.1 connect=1ms service=20ms status=301 bytes=227
2014-11-21T16:46:56.404711+00:00 heroku[router]: at=info method=GET path="/authenticate/twitter?oauth_token=XXXX&oauth_verifier=XXXX" host=teller.happymelly.com request_id=50f15633-fd9d-431b-a132-403821767495 fwd="95.28.27.42" dyno=web.2 connect=1ms service=9ms status=303 bytes=190
2014-11-21T16:46:56.400002+00:00 app[web.2]: [error] application - Unable to log user in. An exception was thrown
2014-11-21T16:46:56.400007+00:00 app[web.2]: securesocial.core.AuthenticationException: null
2014-11-21T16:46:56.400010+00:00 app[web.2]:    at securesocial.core.OAuth1Provider$$anonfun$doAuth$1$$anonfun$apply$8.apply(OAuth1Provider.scala:84) ~[ws.securesocial.securesocial_2.10-2.1.3.jar:2.1.3]
2014-11-21T16:46:56.400012+00:00 app[web.2]:    at securesocial.core.OAuth1Provider$$anonfun$doAuth$1$$anonfun$apply$8.apply(OAuth1Provider.scala:84) ~[ws.securesocial.securesocial_2.10-2.1.3.jar:2.1.3]
2014-11-21T16:46:56.400014+00:00 app[web.2]:    at scala.Option.getOrElse(Option.scala:120) [org.scala-lang.scala-library-2.10.3.jar:na]
2014-11-21T16:46:56.400016+00:00 app[web.2]:    at securesocial.core.OAuth1Provider$$anonfun$doAuth$1.apply(OAuth1Provider.scala:84) ~[ws.securesocial.securesocial_2.10-2.1.3.jar:2.1.3]
2014-11-21T16:46:56.400018+00:00 app[web.2]:    at securesocial.core.OAuth1Provider$$anonfun$doAuth$1.apply(OAuth1Provider.scala:62) ~[ws.securesocial.securesocial_2.10-2.1.3.jar:2.1.3]
2014-11-21T16:46:56.400020+00:00 app[web.2]:    at scala.Option.map(Option.scala:145) [org.scala-lang.scala-library-2.10.3.jar:na]

The pattern is stable. As soon as there's only one request from Twitter everything works fine.

2014-11-21T16:48:41.633181+00:00 heroku[router]: at=info method=GET path="/authenticate/twitter" host=teller.happymelly.com request_id=d3bdb519-8b4e-450e-a650-3ea5a840b90f fwd="95.28.27.42" dyno=web.2 connect=1ms service=679ms status=303 bytes=398
2014-11-21T16:48:42.629072+00:00 heroku[router]: at=info method=GET path="/authenticate/twitter?oauth_token=XXX&oauth_verifier=XXX" host=teller.happymelly.com request_id=740ac75a-1d37-4587-9628-50e703d7ad31 fwd="95.28.27.42" dyno=web.1 connect=1ms service=6ms status=301 bytes=227
2014-11-21T16:48:43.315185+00:00 app[web.2]: [debug] application - GET https://api.twitter.com/1.1/account/settings.json
2014-11-21T16:48:43.351654+00:00 app[web.2]: [debug] application - 200 OK

Did anyone experience such problem? Any suggestions what direction should I dig?

It's very annoying because sometimes visitors have to click 'Login' button 3-4 times. Any help is very appreciated.


Solution

  • To use Secure Social on Heroku :