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

ChannelAdaptor potentially unsafe synchronization #585

Open
agustiza opened this issue Mar 11, 2024 · 2 comments
Open

ChannelAdaptor potentially unsafe synchronization #585

agustiza opened this issue Mar 11, 2024 · 2 comments

Comments

@agustiza
Copy link

Hello everyone,

Skimming through ChannelAdaptor source it seems in this line the disconnectLock is the shared Boolean.TRUE object.

This might be unsafe as someone might inadvertly deadlock the shutdown of a ChannelAdaptor by locking on Boolean.True. Also this would make the lock static in scope given that this lock instance would be shared among all other ChannelAdaptors.

Finally synchronizing against Boolean is warned against by the Java spec as Boolean and a few other java.lang classes are considered ValueBased classes. (See @jdk.internal.ValueBased)

A program may produce unpredictable results if it attempts to distinguish two references to equal values of a value-based class, whether directly via reference equality or indirectly via an appeal to synchronization, identity hashing, serialization, or any other identity-sensitive mechanism

Seems it could be swapped for new Object() without any side effect as far as I could see.

Probably never harmed anyone but better be safe!

Cheers

@agustiza
Copy link
Author

Also it might throw exceptions in future JVM releases according to the JEP-390 https://openjdk.org/jeps/390

Attempts to synchronize on instances of these classes will produce exceptions.

agustiza pushed a commit to agustiza/jPOS that referenced this issue Mar 11, 2024
@agustiza
Copy link
Author

PR

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

No branches or pull requests

1 participant