Skip to content

fix: added synchronous handler timeout to prevent deadlock #10

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CatchABus
Copy link
Contributor

@CatchABus CatchABus commented May 8, 2025

This PR adds a missing runnable wait timeout to avoid deadlock when main thread is too busy to handle the task given.
@farfromrefug I have set it to 300ms but since it blocks main looper, I'll leave it to your judgement.

Closes #7

@farfromrefug
Copy link
Member

@CatchABus i am not sure about the time. Never faced an issue when this happened.
Which function were you calling ?

@CatchABus
Copy link
Contributor Author

CatchABus commented May 11, 2025

@CatchABus i am not sure about the time. Never faced an issue when this happened. Which function were you calling ?

The operation was as basic as adding markers to a cluster layer.
Here's a sample of how it's done:

const data = []; // Let's say this is location data

const clusterLayer = new ClusteredVectorLayer({
    builder: new ClusterElementBuilder({
      buildClusterElement: (position: MapPos, elements: VectorElementVector) => {
        ...
      }
    }),
    dataSource: localDataSource,
    visibleZoomRange: [0, 42]
  });

  for (const item of data) {
    const marker = new Marker({
      projection: cartoMap.projection,
      styleBuilder: ...,
      position: {
        longitude: item.longitude || 0,
        latitude: item.latitude || 0
      }
    });
    
    clusterLayer.add(marker);
  }

The issue occured with 10 markers, leading to a frequent deadlock and app being completely frozen.

To solve this, I have updated my code to append all markers to a VectorElementVector first and consequently add the latter to the cluster layer.

const markerVector: VectorElementVector = new VectorElementVector();

Even though there's a workaround, I believe the wait() without timeout is a bit dangerous to leave as is.

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

Successfully merging this pull request may close these issues.

Bug(android): Deadlock when generating multiple marker clusters
2 participants