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

[Java] ThreadPoolFury and ThreadLocalFury concurrency security issues #1524

Open
LiangliangSui opened this issue Apr 16, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@LiangliangSui
Copy link
Contributor

LiangliangSui commented Apr 16, 2024

Is your feature request related to a problem? Please describe.

  1. org.apache.fury.ThreadLocalFury#processCallback will access the LoaderBinding of all threads, which has potential thread safety issues
// org.apache.fury.ThreadLocalFury
@Override
protected void processCallback(Consumer<Fury> callback) {
  factoryCallback = factoryCallback.andThen(callback);
  // All LoaderBinding
  for (LoaderBinding binding : allFury.keySet()) {
    binding.visitAllFury(callback);
    binding.setBindingCallback(factoryCallback);
  }
}
  1. In org.apache.fury.pool.ThreadPoolFury#processCallback, all ClassLoaderFuryPooled will also be accessed, but traversing allFury and setFactoryCallback does not lock the variables to ensure the safety of the variables.
// org.apache.fury.pool.ThreadPoolFury
@Override
protected void processCallback(Consumer<Fury> callback) {
  factoryCallback = factoryCallback.andThen(callback);
  // All ClassLoaderFuryPooled
  for (ClassLoaderFuryPooled furyPooled :
      furyPooledObjectFactory.classLoaderFuryPooledCache.asMap().values()) {
    furyPooled.allFury.keySet().forEach(callback);
    furyPooled.setFactoryCallback(factoryCallback);
  }
}
// org.apache.fury.pool.ClassLoaderFuryPooled
void setFactoryCallback(Consumer<Fury> factoryCallback) {
  this.factoryCallback = factoryCallback;
}

Describe the solution you'd like

Use lock to ensure variables are thread-safe.

Additional context

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

No branches or pull requests

1 participant