Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session should be fully stored before response is returned #93

Closed
purplefox opened this issue Apr 17, 2015 · 4 comments
Closed

Session should be fully stored before response is returned #93

purplefox opened this issue Apr 17, 2015 · 4 comments

Comments

@purplefox
Copy link
Contributor

In SessionHandlerImpl, the session is stored in the headers end handler, but the store is async, so may not happen until after the next request for that session hits the server.

This could mean the session is not found.

We need to somehow store the session and not send the response back to the client until the session is fully stored.

@maumock
Copy link

maumock commented Apr 30, 2015

Hammer option

    try {
        //Future used to block this thread until all work is complete.
        final CompletableFuture<Void> future = new CompletableFuture<>();
        //Run method async
        CompletableFuture.runAsync(()->{
            this.sessionStore.put(context.session(), res -> {
                if (res.succeeded()) {
                  future.complete(null);
                } else {
                  // Failed to store session
                  context.fail(res.cause());
                  future.completeExceptionally(res.cause());
                }
              });
        }).join();

        //Wait until future is notified to proceed.
        future.get();
        System.out.println("future done");
    } catch (Exception e) {
        context.fail(e);
    }

@leolux
Copy link
Contributor

leolux commented May 5, 2015

Maybe it could be implemented with the BlockingHandlerDecorator from this commit 4ffa350

@purplefox
Copy link
Contributor Author

Now fixed by making headers end handlers take a future (required change in core too)

@apatrida
Copy link

@purplefox is there a chance that storing objects in sessions (clustered w/hazelcast) could have this same issue? we are currently debugging a case where something stored into a session (future URL to redirect towards), is not in the session on the next page which comes quickly. Debugging it is always there (we slow things down when debugging), but randomly fails to be there at other times. Or is it our imagination?

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

No branches or pull requests

4 participants