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
{{ message }}
Repository navigation
Gnome-Keyring Access: RejectedExecutionException on shutdown or JVM shutdown blocked for minutes #2
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.
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 cryptomator1.6.0-SNAPSHOT using the outsourced integrations-api integrations-linux0.2.0-SNAPSHOT depending on my secret-service1.2.4-SNAPSHOT.
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
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.
@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?
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)
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.
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.
For me it looks like the DBusConnection is already closed when you try to unregister your signals.
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)
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
So I guess the problem is really internally with dbus-java or should I also avoid calling DBusConnection.close() or DBusConnection.disconnect() entirely @hypfvieh?
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.
Activity
infeo commentedon Nov 11, 2020
Blocked by swiesend/secret-service#21
swiesend commentedon Nov 12, 2020
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-javaand it seems not to fix theRejectedExecutionException(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
cryptomator1.6.0-SNAPSHOTusing the outsourced integrations-apiintegrations-linux0.2.0-SNAPSHOTdepending on mysecret-service1.2.4-SNAPSHOT.with
dbus-javaHEAD on hypfvieh/dbus-java@c1ee121:all logs:
testing-dbus-3.2.4-SNAPSHOT-c1ee1213ce8aefc33bddeee3567dc1ae3b2c235d.log
the
RejectedExecutionExceptiona blocked shutdown:
overheadhunter commentedon Nov 13, 2020
When Cryptomator is in this state:
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.
swiesend commentedon Nov 13, 2020
@overheadhunter, the
RejectedExecutionExceptionseems to be fixed with the current HEAD ofdbus-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 hereIt seems that my shutdown hook on disconnecting my SignalHandlers waits indefinitely as it does not return from
dbus-javasorg.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?
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
infeo commentedon Nov 13, 2020
No. A thread needs to be marked as daemon before it is started, see the API docs.
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)hypfvieh commentedon Nov 13, 2020
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.
swiesend commentedon Nov 13, 2020
Well, if I can avoid removing the signal handlers manually then everything gets easy.
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
AutoCloseableclasses, 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 theDBusConnection, 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.Remove SignalHandler.disconnect() as unregistering them is unnecessary
swiesend commentedon Nov 13, 2020
SignalHandler.disconnect()method did not help. I could still triggerRejectedExecutionExceptions with two different call stacks (with libsdbus-java-3.2.4-c1ee1213-SNAPSHOT.jarandsecret-service/1.2.4-e03a3ae9-SNAPSHOT, see commitException in thread "Thread-6":and
Exception in thread "DBusConnection":MessageHandler()shutdown hook, which may have calledDBusConnection.disconnect()twice didn't help either secret-service/1.2.4-7a6a9df9-SNAPSHOT, see commitsee all changes since last published version
1.2.3: swiesend/secret-service@v1.2.3...develop-1.0.0So I guess the problem is really internally with
dbus-javaor should I also avoid callingDBusConnection.close()orDBusConnection.disconnect()entirely @hypfvieh?hypfvieh commentedon Nov 14, 2020
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.
swiesend commentedon Nov 16, 2020
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
Merge pull request #1 from swiesend/develop