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

SessionImpl class is not serializable so fails in clustered session store. #89

Closed
wants to merge 1 commit into from
Closed

Conversation

mark-ennis
Copy link

The SessionImpl class is not serializable because is lacks a zero argument constructor. This means that it causes an exception when using sessions with a ClusteredSessionStore. The serialised form created by the writeToBuffer() method does not include the "timeout" field (which results in sessions being discarded as soon as they are referenced from the store) or the "id" field which appears to be needed, although, I did not identify exactly where. I have updated the SessionImpl class to overcome these problems.

@purplefox
Copy link
Contributor

Hi Mark - is this still an issue?

I will close this for now, if it is, please re-open :)

@purplefox purplefox closed this Apr 14, 2015
@mark-ennis
Copy link
Author

Yes, it is still an issue.

Apr 15, 2015 8:28:15 AM io.vertx.ext.apex.impl.RoutingContextImplBase
SEVERE: Unexpected exception in route
com.hazelcast.nio.serialization.HazelcastSerializationException: Problem while reading DataSerializable, namespace: 0, id: 0, class: 'io.vertx.spi.cluster.impl.hazelcast.HazelcastAsyncMap$DataSerializableHolder', exception: Failed to load class io.vertx.ext.apex.sstore.impl.SessionImpl
at com.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:120)
at com.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:39)
at com.hazelcast.nio.serialization.StreamSerializerAdapter.toObject(StreamSerializerAdapter.java:65)
at com.hazelcast.nio.serialization.SerializationServiceImpl.toObject(SerializationServiceImpl.java:260)
at com.hazelcast.spi.impl.NodeEngineImpl.toObject(NodeEngineImpl.java:186)
at com.hazelcast.map.impl.AbstractMapServiceContextSupport.toObject(AbstractMapServiceContextSupport.java:42)
at com.hazelcast.map.impl.DefaultMapServiceContext.toObject(DefaultMapServiceContext.java:28)
at com.hazelcast.map.impl.proxy.MapProxySupport.toObject(MapProxySupport.java:1038)
at com.hazelcast.map.impl.proxy.MapProxyImpl.get(MapProxyImpl.java:84)
at io.vertx.spi.cluster.impl.hazelcast.HazelcastAsyncMap.lambda$get$0(HazelcastAsyncMap.java:46)
at io.vertx.spi.cluster.impl.hazelcast.HazelcastAsyncMap$$Lambda$126/463866392.handle(Unknown Source)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:219)
at io.vertx.core.impl.ContextImpl$$Lambda$6/917831210.run(Unknown Source)
at io.vertx.core.impl.OrderedExecutorFactory$OrderedExecutor.lambda$new$180(OrderedExecutorFactory.java:91)
at io.vertx.core.impl.OrderedExecutorFactory$OrderedExecutor$$Lambda$5/73181251.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Failed to load class io.vertx.ext.apex.sstore.impl.SessionImpl
at io.vertx.spi.cluster.impl.hazelcast.HazelcastAsyncMap$DataSerializableHolder.readData(HazelcastAsyncMap.java:176)
at com.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:111)
... 17 more
Caused by: java.lang.InstantiationException: io.vertx.ext.apex.sstore.impl.SessionImpl
at java.lang.Class.newInstance(Class.java:423)
at io.vertx.spi.cluster.impl.hazelcast.HazelcastAsyncMap$DataSerializableHolder.readData(HazelcastAsyncMap.java:173)
... 18 more
Caused by: java.lang.NoSuchMethodException: io.vertx.ext.apex.sstore.impl.SessionImpl.()
at java.lang.Class.getConstructor0(Class.java:3074)
at java.lang.Class.newInstance(Class.java:408)
... 19 more

@purplefox
Copy link
Contributor

Do you have a reproducer for this?

@mark-ennis
Copy link
Author

package com.viewds.test.vertx.cluster;

import io.vertx.core.AsyncResult;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.http.HttpServer;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.impl.LoggerFactory;
import io.vertx.ext.apex.Router;
import io.vertx.ext.apex.RoutingContext;
import io.vertx.ext.apex.handler.CookieHandler;
import io.vertx.ext.apex.handler.SessionHandler;
import io.vertx.ext.apex.sstore.ClusteredSessionStore;
import io.vertx.ext.apex.sstore.SessionStore;

public class Example
implements Runnable
{
private static final Logger logger =
LoggerFactory.getLogger(Example.class);
private Vertx vertx;

public static void main(String[] args)
{
    new Example(args).run();
}

public Example(String[] args)
{
}

@Override
public void run()
{
    VertxOptions options;

    options = new VertxOptions();
    Vertx.clusteredVertx(options, (AsyncResult<Vertx> event) -> {
        if (event.succeeded()) {
            vertx = event.result();
            startHttpServer();
        }
        else {
            logger.error("failed to obtain vertx object", event.cause());
        }
    });
}

private void startHttpServer()
{
    SessionStore store;
    Router router;

    store = ClusteredSessionStore.create(vertx);

    router = Router.router(vertx);
    router.route().handler(CookieHandler.create());
    router.route().handler(SessionHandler.create(store));
    router.route().handler(this::doSomething);

    vertx.createHttpServer()
            .requestHandler(router::accept)
            .listen(8080, (AsyncResult<HttpServer> event) -> {
                if (event.succeeded()) {
                    logger.info("HTTP server started successfully");
                }
                else {
                    logger.error("HTTP server failed to start",
                            event.cause());
                }
            });
}

private void doSomething(RoutingContext context)
{
    Integer count;

    if ((count = context.session().get("count")) == null) {
        count = 0;
    }
    count += 1;
    context.session().put("count", count);
    context.response()
            .setStatusCode(200)
            .putHeader("Content-type", "text/plain")
            .end("count = " + count + "\n");
}

}

mark-ennis added a commit to mark-ennis/vertx-example that referenced this pull request Apr 16, 2015
@mark-ennis
Copy link
Author

I have put the above code in GitHub. See https://github.com/mark-ennis/vertx-example/tree/master/cluster.

@purplefox
Copy link
Contributor

Thanks Mark, this should be fixed now (PR waiting for review).

The problem here was, although we have clustered session tests, they were all using the fake cluster manager which doesn't actually serialize the sessions.

@mark-ennis
Copy link
Author

Great, thanks.

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

Successfully merging this pull request may close these issues.

2 participants