You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.freedesktop.secret.simple.SimpleCollection;
import static java.util.Optional.*;
public class Application {
public static void main(String[] args) throws IOException {
var collection = new SimpleCollection("My Collection", null);
var attributes = Map.of("example", "secret");
ofNullable(collection.getItems(attributes))
.flatMap(matchingPaths -> matchingPaths.stream().findFirst())
.flatMap(pathToSecret -> ofNullable(collection.getSecret(pathToSecret)))
.ifPresentOrElse(
secret -> System.out.println(new String(secret)),
() -> System.out.println("Not found")
);
collection.lock();
collection.close();
System.out.println("-- Locked & closed the collection");
}
}
I expect this application to exit after printing the last line "-- Locked & closed the collection" to the console.
The program doesn't stop, however. The Debugger shows that the DBusConnection thread is still running.
I'm writing a CLI program in which I would like to make use of this library to connect to the Gnome Keyring. I'd like to prevent having to explicitly call a System.exit(0) since I use a library to manage the lifecycle of parsing options and calling the appropriate functions after parsing the options.
It does work, however, to explicitly call System.exit(0).
The text was updated successfully, but these errors were encountered:
thanks for pointing out this inconsistency and giving a minimal working example.
c386feb will close the dbus connection immediately or at least calls the DBusConnection.close() (dbus-java, 3.3.0) method, which eventually will close all threads. With the fix I could observe that the connection states connected = false, but that the DBusConnection or other DBus {Reader,Sender,Worker} Thread-* threads were sometimes still RUNNING or on WAIT.
Before this fix DBusConnection.close() was only called with a shutdown hook as the DBusConnection is initialized as private static within the SimpleCollection. So the dbus connection were always closed at the end of the lifetime of the SimpleCollection.
I hope this satisfies your expectations, otherwise we will have to track this behavior further down and I guess have to open an issue with dbus-java.
Cool, thanks! I'm taking two weeks off, so I will probably not use the fix before the end of my staycation, but I'll try it asap and let you know if this works for us.
Consider the following application:
I expect this application to exit after printing the last line
"-- Locked & closed the collection"
to the console.The program doesn't stop, however. The Debugger shows that the
DBusConnection
thread is still running.I'm writing a CLI program in which I would like to make use of this library to connect to the Gnome Keyring. I'd like to prevent having to explicitly call a
System.exit(0)
since I use a library to manage the lifecycle of parsing options and calling the appropriate functions after parsing the options.It does work, however, to explicitly call
System.exit(0)
.The text was updated successfully, but these errors were encountered: