Forum Stats

  • 3,757,146 Users
  • 2,251,201 Discussions
  • 7,869,743 Comments

Discussions

Too many sockets with custom socket factory implementation with JSSE

User_I9M6G
User_I9M6G Member Posts: 1 Red Ribbon

Hello,

I've implemented custom socket factory as defined in the JSSE example here: https://docs.oracle.com/javase/10/security/sample-code-illustrating-secure-rmi-connection.htm#JSSEC-GUID-2F82CCFD-22E6-4E6E-A2E1-88CF2BB19E87


When I run my applications, rmi works fine along with ssl. But, what I noticed is that too many threads/ sockets are created. Socket reuse is not happening. When looking for this problem, found out this page: https://docs.oracle.com/javase/7/docs/technotes/guides/rmi/faq.html#customsocketreuse (look for A.5), which expresses the problem with too many socket creation when using custom socket factories. When tried to override the equal and hashcode of custom socket factories, the looking up of remote object in the registry fails during unmarshalling phase. It throws an exception about the serialVersionUID of the custom client socket factory being different from the local class as below.

java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 

java.io.InvalidClassException: ...SslClientSocketFactory; local class incompatible: stream classdesc serialVersionUID = -2466850771396148787, local class serialVersionUID = -8809708706764478887

Defining a static serialVersionUID for SslClientSocketFactory also doesn't work. Throws the same exception. The problem can be that RMI runtime internally uses RMIClientSocketFactory for getting the rmi clients for RMI calls and has a different serialVersionUID for the client socket factory.

Has anyone faced a similar problem and have a solution for this?