[Solved for now]Serializer locked error. What does it mean? Version jme 3.1

Here is the Run time exception. It happen when i initialized the network Client class

client = Network.connectToServer(cd.getNAME(), cd.getVERSION(), cd.getIP(),cd.getTCP_PORT(), cd.getUDP_PORT());

java.lang.RuntimeException: Serializer registry locked trying to register class:class com.jme3.network.message.SerializerRegistrationsMessage
at com.jme3.network.serializing.Serializer.registerClassForId(Serializer.java:195)
at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:237)
at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:151)
at com.jme3.network.service.serializer.ClientSerializerRegistrationsService.onInitialize(ClientSerializerRegistrationsService.java:57)
at com.jme3.network.service.serializer.ClientSerializerRegistrationsService.onInitialize(ClientSerializerRegistrationsService.java:49)
at com.jme3.network.service.AbstractService.initialize(AbstractService.java:74)
at com.jme3.network.service.AbstractService.initialize(AbstractService.java:44)
at com.jme3.network.service.ServiceManager.addService(ServiceManager.java:110)
at com.jme3.network.service.ClientServiceManager.addService(ClientServiceManager.java:75)
at com.jme3.network.base.DefaultClient.addStandardServices(DefaultClient.java:103)
at com.jme3.network.base.DefaultClient.(DefaultClient.java:92)
at com.jme3.network.base.DefaultClient.(DefaultClient.java:98)
at com.jme3.network.Network.connectToServer(Network.java:167)
at junglesurvival.gestion.singleplayer.TheGameSingle.connectionControl.ClientAPI.startClient(ClientAPI.java:23)
at junglesurvival.gestion.singleplayer.TheGameSingle.Loading.loader(Loading.java:62)
at junglesurvival.gestion.singleplayer.Game.menu(Game.java:59)
at junglesurvival.Gestion.gestion(Gestion.java:68)
at junglesurvival.Main.simpleUpdate(Main.java:143)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:246)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:152)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:192)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:233)
at java.lang.Thread.run(Thread.java:745)

Someone else reported a similar issue but then never replied with answers to any of my questions.

Is this when connecting the first time with this client or the second time?

In 3.1, some new default behavior was added that automatically synchronizes the server serializers with the client upon connection but the error you get indicates that it was already done once.

It happen every time i run the game, on the first connection, I will try to restart the pc maybe the connection never close.

Well, it would be within the same process. Double check that you aren’t connecting to the server twice by accident or something.

The flag that it’s complaining about should only be set as part of connecting to a server… so the exception should only happen when connecting a second time within the same JVM process.

Edit: which by the way is a bug, too… but I’m just confirming it’s the same bug.

I do not connect twice during the same instance. I did a system out print to make sure and I restarted the computer to make sure no connection were alive.

I hope the information will help out. If you need more information just ask I will reply as fast as possible!

Are you running a client and a server in the same instance?

I thought the same thing i was writing down when you answered :stuck_out_tongue:

"I was wondering, is it possible if i start a server on the same instance of the application it could cause this kind of bug?

Maybe it never unlock the Serializer"

Well, the serializer is locked on purpose when the server starts so that you don’t accidentally add classes after the serializer list has been compiled.

…but I stupidly didn’t take into account the case where a client and server run together. But really, Serializer isn’t smart here either as there is no reason to register the same classes twice. I should probably just modify the Serializer to see if the class is already registered before checking the read-only lock.

In the mean time, you can work around this bug by disabling that service. Most people are probably already registering their own classes anyway. (Though the default services I wrote all expect the client to automatically get message classes registered… that’s another story that shouldn’t affect you.)

Removing it on the server alone might be enough. Something like:
server.getServices().removeService(server.getServices().getService(ServerSerializerRegistrationsService.class));

…before you start the server.

Alright thank you!

Note: I just fixed this bug on master. I also modified the TestChatClient and TestChatServer to be slightly better examples (better error/connection state handling, etc.) and then added a TestChatClientAndServer that runs a client and server in the same JVM. I used this to test the bug.

With this bug fixed, the default services can be left in place and so the client doesn’t need to register serializers anymore. The server will send the client the registry during connect.

3 Likes

Thank you for everything.

I think this “bug” is still occuring when running two servers in the same JVM - I’m pretty sure it isn’t a good practice to do such thing, but I just thought it should be mentioned. Maybe I’m wrong, but creating a second server (on another port etc.) throws this exception:

java.lang.RuntimeException: Serializer registry locked trying to register class:class com.jme3.network.message.SerializerRegistrationsMessage
at com.jme3.network.serializing.Serializer.registerClassForId(Serializer.java:196)
at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:238)
at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:152)
at com.jme3.network.service.serializer.ServerSerializerRegistrationsService.onInitialize(ServerSerializerRegistrationsService.java:53)
at com.jme3.network.service.serializer.ServerSerializerRegistrationsService.onInitialize(ServerSerializerRegistrationsService.java:48)
at com.jme3.network.service.AbstractService.initialize(AbstractService.java:74)
at com.jme3.network.service.AbstractService.initialize(AbstractService.java:44)
at com.jme3.network.service.ServiceManager.addService(ServiceManager.java:126)
at com.jme3.network.service.HostedServiceManager.addService(HostedServiceManager.java:82)
at com.jme3.network.base.DefaultServer.addStandardServices(DefaultServer.java:112)
at com.jme3.network.base.DefaultServer.(DefaultServer.java:100)
at com.jme3.network.Network.createServer(Network.java:95)
at com.jme3.network.Network.createServer(Network.java:63)

(Using the latest 3.1 master build)

I guess, removing the ServerSerializerRegistrationsService would work for my purposes.

Yeah, you’ll have to. SpiderMonkey is not meant to work in the way you are using it… don’t even know why you are doing it either.

Serializer is a global singleton so you get lots of weird stuff if you try to host multiple different games in the same VM. If you just want different ports for the same game then that is already supported without going through all of that trouble.