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

In EmbeddedSlotMap class Query Method stuck in infinite Loop. #1429

Open
birla94 opened this issue Dec 18, 2023 · 2 comments
Open

In EmbeddedSlotMap class Query Method stuck in infinite Loop. #1429

birla94 opened this issue Dec 18, 2023 · 2 comments

Comments

@birla94
Copy link

birla94 commented Dec 18, 2023

When attempting to retrieve the value of a script variable using Java classes, the process attempts to fetch the value from EmbeddedSlotMap using the query method, but the thread becomes stuck in this operation, leading to the necessity of restarting the application.

I'm seeking assistance for a potential solution or any feasible resolution within the existing code. I suspect that the issue may be related to cyclic linked list values in the SlotMap, causing the thread to become stuck. Any insights or suggestions on how to address this concern would be greatly appreciated.

/** Locate the slot with the given name or index. */
   @Override
   public Slot query(Object key, int index) {
       if (slots == null) {
           return null;
       }

       int indexOrHash = (key != null ? key.hashCode() : index);
       int slotIndex = getSlotIndex(slots.length, indexOrHash);
       for (Slot slot = slots[slotIndex]; slot != null; slot = slot.next) {
           if (indexOrHash == slot.indexOrHash && Objects.equals(slot.name, key)) {
               return slot;
           }
       }
       return null;
   }
@rPraml
Copy link
Contributor

rPraml commented Feb 3, 2024

Hello @birla94,

is this reproduceable in your environment? Could it be a concurrent issue? (multiple threads, that access the map?)

I'm seeking assistance for a potential solution or any feasible resolution within the existing code

Can you build a custom version? Maybe you can add some asserts or a counter that will exit the loop and dump the valve, when a cycle was detected.

(I saw an interesting video on YT about efficient cycle detection https://youtu.be/d_hVz6SaF3w - maybe others can check, if it is worth to implement here and throw a code bug exception - AFAIK this method is very hot code)

@p-bakker
Copy link
Collaborator

p-bakker commented Feb 4, 2024

Any chance you might have a cyclic prototype setup, like object A has object B as prototype, but B has A as prototype?

Such a setup I think could result in an endless loop if the property you're trying to retrieve doesn't exist on either A or B

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

3 participants