Skip to content

Gnome-Keyring Access: RejectedExecutionException on shutdown or JVM shutdown blocked for minutes  #2

Closed

Description

@infeo

This is just a bridge issue for cryptomator/cryptomator#1403 in the down-stream project.

Sometimes, if the Gnome-Keyring is probed/used by accessing the DBus, an exception is thrown at shutdown:

Exception in thread "DBusConnection" java.util.concurrent.RejectedExecutionException: Task org.freedesktop.dbus.connections.AbstractConnection$1@e855db7 rejected from java.util.concurrent.ThreadPoolExecutor@3fcbf031[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 45]
	at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.reject(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.execute(Unknown Source)
	at org.freedesktop.dbus.connections.AbstractConnection.sendMessage(AbstractConnection.java:378)
	at org.freedesktop.dbus.connections.AbstractConnection.handleMessage(AbstractConnection.java:1054)
	at org.freedesktop.dbus.connections.AbstractConnection.handleMessage(AbstractConnection.java:713)
	at org.freedesktop.dbus.connections.IncomingMessageThread.run(IncomingMessageThread.java:43)

On other occasions, the shutdown is blocked by something at least several minutes.

Activity

  1. added
    bug
    on Nov 11, 2020
  2. infeo commented on Nov 11, 2020

    @infeo
    MemberAuthor
  3. swiesend commented on Nov 12, 2020

    @swiesend
    Contributor

    Wow, @infeo that is some very in depth bug tracking for hypfvieh/dbus-java#123! Thank you for writing the issue, which I ignored way too long and feel guilty of not having it investigated better.

    So I tested it with the current HEAD of dbus-java and it seems not to fix the RejectedExecutionException (1/50 times) and neither the blocked shutdown (2/50 times with a duration of about 5 min) of 50 graceful cryptomator shutdowns.

    I tested with a local cryptomator 1.6.0-SNAPSHOT using the outsourced integrations-api integrations-linux 0.2.0-SNAPSHOT depending on my secret-service 1.2.4-SNAPSHOT.

    with dbus-java HEAD on hypfvieh/dbus-java@c1ee121:

    commit c1ee1213ce8aefc33bddeee3567dc1ae3b2c235d (HEAD -> master, origin/master, origin/HEAD)
    Author: David M <[email protected]>
    Date:   Wed Nov 11 17:39:03 2020 +0100
    
        Implemented some of the suggestions from #123
    

    all logs:
    testing-dbus-3.2.4-SNAPSHOT-c1ee1213ce8aefc33bddeee3567dc1ae3b2c235d.log

    the RejectedExecutionException

    sebastian@home:~/develop/github/cryptomator/cryptomator/main$ buildkit-linux/launcher-linux.sh
    23:33:36.899 [main] DEBUG org.cryptomator.common.Environment - java.library.path: /usr/local/cuda-11.1/lib64:/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
    23:33:36.903 [main] DEBUG org.cryptomator.common.Environment - user.language: en
    23:33:36.904 [main] DEBUG org.cryptomator.common.Environment - user.region: null
    23:33:36.904 [main] DEBUG org.cryptomator.common.Environment - logback.configurationFile: null
    23:33:36.904 [main] DEBUG org.cryptomator.common.Environment - cryptomator.settingsPath: ~/.config/Cryptomator/settings.json
    23:33:36.904 [main] DEBUG org.cryptomator.common.Environment - cryptomator.ipcPortPath: ~/.config/Cryptomator/ipcPort.bin
    23:33:36.904 [main] DEBUG org.cryptomator.common.Environment - cryptomator.keychainPath: null
    23:33:36.904 [main] DEBUG org.cryptomator.common.Environment - cryptomator.logDir: ~/.local/share/Cryptomator/logs
    23:33:36.904 [main] DEBUG org.cryptomator.common.Environment - cryptomator.mountPointsDir: ~/.local/share/Cryptomator/mnt
    23:33:36.904 [main] DEBUG org.cryptomator.common.Environment - cryptomator.minPwLength: null
    23:33:36.904 [main] DEBUG org.cryptomator.common.Environment - cryptomator.buildNumber: null
    23:33:36.942 [main] DEBUG org.cryptomator.common.ShutdownHook - Registered shutdown hook.
    23:33:37.017 [main] DEBUG org.cryptomator.common.settings.SettingsProvider - Attempting to load settings from /home/sebastian/.config/Cryptomator/settings.json
    23:33:37.066 [main] WARN org.cryptomator.common.settings.SettingsJsonAdapter - Unsupported vault setting found in JSON: keychainBackend
    23:33:37.066 [main] INFO org.cryptomator.common.settings.SettingsProvider - Settings loaded from /home/sebastian/.config/Cryptomator/settings.json
    23:33:37.747 [main] INFO  org.cryptomator.launcher.Cryptomator - Starting Cryptomator 1.6.0-SNAPSHOT on Linux 5.4.0-53-generic (amd64)
    23:33:37.987 [JavaFX Application Thread] INFO  o.c.ui.launcher.FxApplicationStarter - JavaFX Runtime started.
    Exception in thread "DBusConnection" java.util.concurrent.RejectedExecutionException: Task org.freedesktop.dbus.connections.AbstractConnection$3@76756d94 rejected from java.util.concurrent.ThreadPoolExecutor@573f8321[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
    	at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2057)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:827)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1357)
    	at org.freedesktop.dbus.connections.AbstractConnection.executeInWorkerThreadPool(AbstractConnection.java:946)
    	at org.freedesktop.dbus.connections.AbstractConnection.handleMessage(AbstractConnection.java:920)
    	at org.freedesktop.dbus.connections.AbstractConnection.handleMessage(AbstractConnection.java:709)
    	at org.freedesktop.dbus.connections.IncomingMessageThread.run(IncomingMessageThread.java:43)
    23:33:41.800 [App Background Thread 003] INFO  o.c.ui.unlock.UnlockWorkflow - Unlock of 'sebastian' succeeded.
    23:33:41.918 [DBus Worker Thread-2] INFO  o.f.secret.handlers.SignalHandler - Received signal Collection.ItemChanged: /org/freedesktop/secrets/collection/login/478
    23:33:41.937 [DBus Worker Thread-3] INFO  o.f.secret.handlers.SignalHandler - Received signal Collection.ItemChanged: /org/freedesktop/secrets/collection/login/478
    23:33:45.495 [JavaFX Application Thread] INFO  o.cryptomator.ui.fxapp.UpdateChecker - Current version: 1.6.0-SNAPSHOT, lastest version: 1.5.8
    

    a blocked shutdown:

    sebastian@home:~/develop/github/cryptomator/cryptomator/main$ buildkit-linux/launcher-linux.sh 
    23:23:17.440 [main] DEBUG org.cryptomator.common.Environment - java.library.path: /usr/local/cuda-11.1/lib64:/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - user.language: en
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - user.region: null
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - logback.configurationFile: null
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - cryptomator.settingsPath: ~/.config/Cryptomator/settings.json
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - cryptomator.ipcPortPath: ~/.config/Cryptomator/ipcPort.bin
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - cryptomator.keychainPath: null
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - cryptomator.logDir: ~/.local/share/Cryptomator/logs
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - cryptomator.mountPointsDir: ~/.local/share/Cryptomator/mnt
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - cryptomator.minPwLength: null
    23:23:17.445 [main] DEBUG org.cryptomator.common.Environment - cryptomator.buildNumber: null
    23:23:17.492 [main] DEBUG org.cryptomator.common.ShutdownHook - Registered shutdown hook.
    23:23:17.573 [main] DEBUG org.cryptomator.common.settings.SettingsProvider - Attempting to load settings from /home/sebastian/.config/Cryptomator/settings.json
    23:23:17.626 [main] WARN org.cryptomator.common.settings.SettingsJsonAdapter - Unsupported vault setting found in JSON: keychainBackend
    23:23:17.626 [main] INFO org.cryptomator.common.settings.SettingsProvider - Settings loaded from /home/sebastian/.config/Cryptomator/settings.json
    23:23:18.250 [main] INFO  org.cryptomator.launcher.Cryptomator - Starting Cryptomator 1.6.0-SNAPSHOT on Linux 5.4.0-53-generic (amd64)
    23:23:18.510 [JavaFX Application Thread] INFO  o.c.ui.launcher.FxApplicationStarter - JavaFX Runtime started.
    23:23:22.532 [App Background Thread 003] INFO  o.c.ui.unlock.UnlockWorkflow - Unlock of 'sebastian' succeeded.
    23:23:22.642 [DBus Worker Thread-2] 
    INFO  o.f.secret.handlers.SignalHandler - Received signal Collection.ItemChanged: /org/freedesktop/secrets/collection/login/478
    23:23:22.665 [DBus Worker Thread-3] INFO  o.f.secret.handlers.SignalHandler - Received signal Collection.ItemChanged: /org/freedesktop/secrets/collection/login/478
    23:23:24.858 [JavaFX Application Thread] INFO  o.cryptomator.ui.quit.QuitController - Locked sebastian
    23:23:24.867 [main] INFO  org.cryptomator.launcher.Cryptomator - UI shut down
    
    ^C
    
    
    ^C
    
    ^C^C^C
    
  4. overheadhunter commented on Nov 13, 2020

    @overheadhunter
    Member

    When Cryptomator is in this state:

    ^C
    
    
    ^C
    
    ^C^C^C
    

    Can you take a look into VisualVM and see what threads are still running? At least for the shutdown issue, it might be sufficient to make these blocking threads daemon threads.

  5. swiesend commented on Nov 13, 2020

    @swiesend
    Contributor

    @overheadhunter, the RejectedExecutionException seems to be fixed with the current HEAD of dbus-java, but the blocked shutdown not so much (occured 3/50 times). I actually tested yesterday evening with a wrong cryptomator build as @hypfvieh pointed out here

    It seems that my shutdown hook on disconnecting my SignalHandlers waits indefinitely as it does not return from dbus-javas org.freedesktop.dbus.messages.MethodCall.getReply(), or how is this call stack to read?

    So how do I make this shutdown hook thread a daemon thread? Just like that?

    Thread.currentThread().setDaemon(true)

    Screenshot from 2020-11-13 14-16-33

    Screenshot from 2020-11-13 14-20-51

    dumps:
    threaddump-1605272028171.tdump.log
    threaddump-1605272048273.tdump.log

    Cryptomator shutdowns:
    2020-11-13_cryptomator_1.6.0-8e56218f-SNAPSHOT_shutdowns.log

    with correct versions:
    1.6.0-8e56218f-SNAPSHOT_libs.log

  6. infeo commented on Nov 13, 2020

    @infeo
    MemberAuthor

    So how do I make this shutdown hook thread a daemon thread? Just like that?

    No. A thread needs to be marked as daemon before it is started, see the API docs.

    It seems that my shutdown hook on disconnecting my SignalHandlers waits indefinitely as it does not return from dbus-javas org.freedesktop.dbus.messages.MethodCall.getReply(), or how is this call stack to read?

    I would also draw this conclusion. But i don't know if marking a shutdown hook as daemon solves this, since when the shutdown hook is executed we are already in the shutdown phase. Another approach is to reduce the waiting time for the reply by calling MethodCall.setDefaultTimeout(). But this has the drawback to change the return time globally, so it should be used with care.

    (There is actually a getReply(long timeout) method, but it is not used)

  7. hypfvieh commented on Nov 13, 2020

    @hypfvieh

    I agree with the findings.

    For me it looks like the DBusConnection is already closed when you try to unregister your signals.
    As the threadpool for handling signals is already closed in DBusConnection, the getReply method will hang "forever" or at least for a very long time.

    Shutdown hooks are always a bit fuzzy and should be avoided.
    The hook may never be called (e.g. on SIGINT, SIGKILL or other 'crashing' cause), also hooks are called in a random order.

    Turning your hook to a daemon thread is one option, so it will get killed on JVM shutdown even if it is not finished.
    But do you really need to clean up?

    When closing the DBus connection you usually don't have to cleanup, because DBus (and dbus-java) will take care of that.
    Closing the Connection will trigger an unregister action on DBus, so everything is removed related to that connection.

  8. swiesend commented on Nov 13, 2020

    @swiesend
    Contributor

    Turning your hook to a daemon thread is one option, so it will get killed on JVM shutdown even if it is not finished.
    But do you really need to clean up?

    When closing the DBus connection you usually don't have to cleanup, because DBus (and dbus-java) will take care of that.
    Closing the Connection will trigger an unregister action on DBus, so everything is removed related to that connection.

    Well, if I can avoid removing the signal handlers manually then everything gets easy.

    Shutdown hooks are always a bit fuzzy and should be avoided.

    Yes, they are just the result of my flawed 1.0.0 SimpleCollection API design. I think I have to provide the 2.0.0 API asap with different AutoCloseable classes, that distinguish between a simple-service, -session and a -collection for the Secret Service API.
    Currently I need the shutdown hook, because the there is this static isAvailable() method, that creates the DBusConnection, that may or may not be used by the instance of that class. And if the connection does not get used has to tear it down somehow.

  9. swiesend commented on Nov 13, 2020

    @swiesend
    Contributor

    For me it looks like the DBusConnection is already closed when you try to unregister your signals.

    1. Well, removing my SignalHandler.disconnect() method did not help. I could still trigger RejectedExecutionExceptions with two different call stacks (with libs dbus-java-3.2.4-c1ee1213-SNAPSHOT.jar and secret-service/1.2.4-e03a3ae9-SNAPSHOT, see commit

    Exception in thread "Thread-6":

    17:00:56.235 [main] INFO  org.cryptomator.launcher.Cryptomator - Starting Cryptomator 1.6.2-8e56218f-SNAPSHOT on Linux 5.4.0-53-generic (amd64)
    17:00:56.466 [JavaFX Application Thread] INFO  o.c.ui.launcher.FxApplicationStarter - JavaFX Runtime started.
    17:01:00.392 [App Background Thread 003] INFO  o.c.ui.unlock.UnlockWorkflow - Unlock of 'sebastian' succeeded.
    17:01:02.826 [JavaFX Application Thread] INFO  o.cryptomator.ui.quit.QuitController - Locked sebastian
    17:01:02.837 [main] INFO  org.cryptomator.launcher.Cryptomator - UI shut down
    Exception in thread "Thread-6" java.util.concurrent.RejectedExecutionException: Task org.freedesktop.dbus.connections.AbstractConnection$1@6ff60d89 rejected from java.util.concurrent.ThreadPoolExecutor@6bc984af[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 38]
    	at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2057)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:827)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1357)
    	at org.freedesktop.dbus.connections.AbstractConnection.sendMessage(AbstractConnection.java:380)
    	at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:149)
    	at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:228)
    	at com.sun.proxy.$Proxy22.RemoveMatch(Unknown Source)
    	at org.freedesktop.dbus.connections.impl.DBusConnection.removeSigHandler(DBusConnection.java:818)
    	at org.freedesktop.dbus.connections.AbstractConnection.removeSigHandler(AbstractConnection.java:402)
    	at org.freedesktop.dbus.handlers.SignalHandler.disconnect(SignalHandler.java:63)
    	at org.freedesktop.dbus.handlers.SignalHandler.lambda$new$0(SignalHandler.java:30)
    	at java.base/java.lang.Thread.run(Thread.java:832)
    

    and
    Exception in thread "DBusConnection":

    Exception in thread "DBusConnection" java.util.concurrent.RejectedExecutionException: Task org.freedesktop.dbus.connections.AbstractConnection$1@3af9e58b rejected from java.util.concurrent.ThreadPoolExecutor@39f79f2f[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 39]
    	at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2057)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:827)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1357)
    	at org.freedesktop.dbus.connections.AbstractConnection.sendMessage(AbstractConnection.java:380)
    	at org.freedesktop.dbus.connections.AbstractConnection.handleMessage(AbstractConnection.java:1058)
    	at org.freedesktop.dbus.connections.AbstractConnection.handleMessage(AbstractConnection.java:717)
    	at org.freedesktop.dbus.connections.IncomingMessageThread.run(IncomingMessageThread.java:43)
    
    1. Removing my duplicate MessageHandler() shutdown hook, which may have called DBusConnection.disconnect() twice didn't help either secret-service/1.2.4-7a6a9df9-SNAPSHOT, see commit
    17:21:19.290 [main] INFO  org.cryptomator.launcher.Cryptomator - Starting Cryptomator 1.6.2-8e56218f-SNAPSHOT on Linux 5.4.0-53-generic (amd64)
    17:21:19.528 [JavaFX Application Thread] INFO  o.c.ui.launcher.FxApplicationStarter - JavaFX Runtime started.
    17:21:23.583 [App Background Thread 003] INFO  o.c.ui.unlock.UnlockWorkflow - Unlock of 'sebastian' succeeded.
    17:21:27.034 [JavaFX Application Thread] INFO  o.cryptomator.ui.fxapp.UpdateChecker - Current version: 1.6.2-8e56218f-SNAPSHOT, lastest version: 1.5.8
    17:21:27.888 [JavaFX Application Thread] INFO  o.cryptomator.ui.quit.QuitController - Locked sebastian
    17:21:27.899 [main] INFO  org.cryptomator.launcher.Cryptomator - UI shut down
    ^[[A
    
    
    ^C^C^C
    

    see all changes since last published version 1.2.3: swiesend/secret-service@v1.2.3...develop-1.0.0

    So I guess the problem is really internally with dbus-java or should I also avoid calling DBusConnection.close() or DBusConnection.disconnect() entirely @hypfvieh?

  10. hypfvieh commented on Nov 14, 2020

    @hypfvieh

    No you should not omit the disconnect.

    I made some small changes to dbus-java maybe you try again with these changes.

    The main problem seems to be that the IncomingMessageThread is using a blocking read call on an InputStream.
    This will not be interrupted by Thread.interrupt or by changing the boolean run condition.
    It will only stop reading if the socket gets closed. But this will cause other side effects.

    I changed the disconnect method to set the connection status boolean first and then try to do disconnect stuff.
    Even if the IncomingMessageThread is not terminated by terminate() method (due to the blocking read), it will be killed later on when the transport connection is closed.

  11. swiesend commented on Nov 16, 2020

    @swiesend
    Contributor

    Yes, @hypfvieh I think hypfvieh/dbus-java@bbe26f8 did the trick.

    I wasn't able to trigger any Exception or running into a blocked state, see:
    1.6.0-8e56218f-dbus-java-bbe26f89-terminating-connection-properly-SNAPSHOT.log

  12. linked a pull request that will close this issueUse secret-service 1.5.0 #1on Feb 22, 2021
  13. added a commit that references this issue on Feb 22, 2021
    d0688e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions