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

potential clash while tracking pending requests in CaliforniumLwM2mRequestSender #166

Closed
balsmn opened this issue Aug 16, 2016 · 3 comments
Labels
new feature New feature from LWM2M specification server Impact LWM2M server

Comments

@balsmn
Copy link
Contributor

balsmn commented Aug 16, 2016

CaliforniumLwM2mRequestSender uses a ConcurrentNavigableMap#L57 for tracking pendingRequests before sending it using a coap endpoint. The key is of the format registrationId#requestId and the key generation uses hashCode()#L257

I suppose, the implementation assumes the hashCode to be unique to track pendingRequests and I assume it is implemented in this way to avoid use of ConcurrentMap<String, Collection<requestId>> for tracking all pending requests for a given registrationId. If the assumption is correct, then it is really clever way of doing it. 👍

Only one problem to it. Unfortunately the hashCode is not implemented and left to the default java Object's implementation.

Now as per java doc of hashCode

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java(tm) programming language.)

However, when on morden machines we have 64 bit address space and when mapped to 32 bit integer we will have clashes in hashCode. Also the hashCode algorithm can be influenced using the java VM parameter like -XX:hashCode=2 (which always returns 1 for all hashCode() calls).

The hashCode alogirthm also differs widely from Java 7 to Java 8.

@sbernard31
Copy link
Contributor

Good catch.
What do you propose to replace hashcode() ? UUID ?

@balsmn
Copy link
Contributor Author

balsmn commented Aug 18, 2016

Yes, we can use UUID in that place to maintain the uniqueness

@sbernard31
Copy link
Contributor

It seems default java UUID is not so efficient
(We probably don't care for now as we probably faced more important performance issue)

Did you faced the problem you described ?

@sbernard31 sbernard31 added new feature New feature from LWM2M specification server Impact LWM2M server labels Jan 6, 2017
danielhqv pushed a commit to husqvarnagroup/leshan that referenced this issue Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature from LWM2M specification server Impact LWM2M server
Projects
None yet
Development

No branches or pull requests

2 participants