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

Make DroidDetector thread-safe #44

Open
anjackson opened this issue Aug 14, 2022 · 0 comments
Open

Make DroidDetector thread-safe #44

anjackson opened this issue Aug 14, 2022 · 0 comments

Comments

@anjackson
Copy link
Member

anjackson commented Aug 14, 2022

As noted in the README the DroidDetector is not thread-safe.

This is because we are re-using three DROID objects here:

// Set up DROID binary handler:
private BinarySignatureIdentifier binarySignatureIdentifier;
private ContainerSignatureDefinitions containerSignatureDefinitions;
private static final String FORWARD_SLASH = "/";
private static final String BACKWARD_SLASH = "\\";
private long maxBytesToScan = -1;
boolean archives = false;
private uk.gov.nationalarchives.droid.core.CustomResultPrinter resultPrinter;

If I'm remembering correctly, the issue here is that creating instances of these classes is expensive, and involves mucking around like extracting signature files to temporary locations for loading. Instantiating these classes per-identification would be extremely slow and brittle.

It's not 100% clear if the underlying DROID objects are themselves thread-safe. Therefore, it might be simplest to make them ThreadLocal and take more care with the temporary file code so the per-thread instances don't collide. If they are threadsafe, we may be able to statically declare them, although I'm not sure how configuration would be affected.

Obviously, it'd be good to have a unit test that put the thread-safety under a reasonable amount of strain.

n.b. Issue raised following conversation with @tballison

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