diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java index c0221fad3..649cede10 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java @@ -45,6 +45,7 @@ public class CloudSearch { } final ImportKeysList results = new ImportKeysList(servers.size()); + ArrayList<Thread> searchThreads = new ArrayList<>(); for (final Keyserver keyserver : servers) { Runnable r = new Runnable() { @Override @@ -57,19 +58,25 @@ public class CloudSearch { results.finishedAdding(); // notifies if all searchers done } }; - new Thread(r).start(); + Thread searchThread = new Thread(r); + searchThreads.add(searchThread); + searchThread.start(); } // wait for either all the searches to come back, or 10 seconds - synchronized(results) { + synchronized (results) { try { results.wait(10 * SECONDS); + for (Thread thread : searchThreads) { + // kill threads that haven't returned yet + thread.interrupt(); + } } catch (InterruptedException e) { } } if (results.outstandingSuppliers() > 0) { - String message = "Launched " + servers.size() + " cloud searchers, but" + + String message = "Launched " + servers.size() + " cloud searchers, but" + results.outstandingSuppliers() + "failed to complete."; problems.add(new Keyserver.QueryFailedException(message)); } |