-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Possible race condition when disconnecting #123
Comments
I implemented some of the suggestions. Please try if you can reproduce the issue using the latest changes. |
Hey @hypfvieh! First of all a huge thank you for providing this lib and maintaining it with such quick replies! I had a chance to test your changes, but unfortunately that didn't play out. I documented my test here: |
Are you sure you use the latest git revision? The line numbers reported in the exception do not match. |
Your were absolutely right @hypfvieh. I started a wrong cryptomator build with old dependencies. I was quite confused yesterday evening as I couldn't observe the
But I still have problems on tearing down, as documented here. |
I still can trigger the |
Seems to be fixed, see cryptomator/integrations-linux#2 |
Summary
There is a possible race condition when closing the connection to the DBus via the
DBusConnection
class leading to anjava.util.concurrent.RejectedExecutionException
.Description
In swiesend/secret-service#21 a problem is encountered where after a successfully established DBus connection with the
DBusConnection
class and the (later happend) disconnect, still at least one message is tried to handled. Because the appearance of the problem is intermittent, it may be a race condition. The exception stacktrace:It seems that the
workerThreadPoolExecutor
was already terminated when the message should be handled. Looking at docs of the ThreadPoolExecutor, there are three cases where it is shutdown:shutdown()
shutdownNow()
The first two cases happen only in either in the
changeThreadCount()
ordisconnectInternal()
method of theAbstractConnection
class. The first one basically transfers all jobs to a new executor in a thread safe manner, hence it should impose no problem.The second,
disconnectInternal()
, is therefore the one I looked at. The DBusConnection is an object which recieves, send and handle messages. Currently, first the handling is closed and afterwards the recieving part.dbus-java/dbus-java/src/main/java/org/freedesktop/dbus/connections/AbstractConnection.java
Lines 542 to 563 in ecb3ad0
The message source is the
IncomingMessageThread
. This object is terminated via a variable:While I'm not a fan of closing the message source after closing the handling, more critical is that neither the
connected
variable norterminate
are volatile. This could lead to a cache coherence problem (see https://www.baeldung.com/java-volatile#volatile).Suggested Fix
Make the variables
connected
andterminate
volatile.Additionally, i suggest to first close the message source (setting
terminate
tofalse
) before shutting down the executor.As a third point, maybe the
setTerminate(boolean _terminate)
method can be refactored toterminate()
to only terminate the connection and not setting it to any value.The text was updated successfully, but these errors were encountered: