0

I am using the play-silhouette-library version 2.0.2 for my authentication on my website.

Right now I have this method that activates when the user signs out:

def signOut(url: String) = SecuredAction.async { implicit request =>
    val result = Future.successful(Redirect(url))
    env.eventBus.publish(LogoutEvent(request.identity, request, request2lang))
    request.authenticator.discard(result)
}

However, on Chrome only (not Firefox), the user fails to sign out about 40% of the time. I believed that this was due to some sort of race condition with the authenticator discard, so as a quick test I added Thread.sleep(20) before the authenticator discard:

def signOut(url: String) = SecuredAction.async { implicit request =>
    val result = Future.successful(Redirect(url))
    env.eventBus.publish(LogoutEvent(request.identity, request, request2lang))
    Thread.sleep(20)
    request.authenticator.discard(result)
}

and the problem would not occur. However, adding a Thread.sleep() call isn't exactly production-ready code, so I'm having a hard time coming up with a solution.

I tried:

def signOut(url: String) = SecuredAction.async { implicit request =>
    val publish = Future.successful(
      env.eventBus.publish(LogoutEvent(request.identity, request, request2lang))
    )
    Await.ready(publish, Duration.Inf)
    request.authenticator.discard(Future(Redirect(url)))
}

But that did not fix the issue. I am inexperienced with this kind of problem and would love some help.

3
  • The story you tell sounds strange to me. Do you handle LogoutEvent in your custom code in any way? Is the issue still reproducible if you move Thread.sleep before the publish call?
    – SergGr
    Jan 8, 2019 at 22:51
  • @SergGr, I don't use LogoutEvents anywhere else in our code, but interestingly a Thread.sleep before the publish call fixed the issue as well. I suppose that indicates some sort of conflict elsewhere? Jan 9, 2019 at 22:50
  • Lukas, exactly! IMHO this test proves that if there is a concurrency conflict it is not within your signOut but with something else. It is hard to guess where from what I know now. Most probably the next step I'd try to investigate is what is the difference between Chrome and Firefox: analyze all requests around signout and their timings in both browsers to see if this is a race condition between processing two requests (and for example Firefox is not fast enough to issue two request concurrently).
    – SergGr
    Jan 9, 2019 at 23:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.