-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #244: Fixed issue with shared connections failing when dbus dae…
…mon disconnected before This issue is triggered when shared connections are enabled (default) and you create a connection to a DBus daemon, then the daemon is restarted (process killed and restarted) causing your connection to be closed. When retrying to connect to the restarted DBus Daemon the shared-feature will try to reuse the existing connection even though the underlying transport already disconnected. This patch will check the transport connection status on shared connections before re-using them. If the transport is closed/broken the stored connection reference will be removed and a new connection is created. Otherwise if transport is still ok, the same connection is returned (like before).
- Loading branch information
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
dbus-java-tests/src/test/java/sample/issue/Issue244Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package sample.issue; | ||
|
||
import org.freedesktop.dbus.bin.EmbeddedDBusDaemon; | ||
import org.freedesktop.dbus.connections.BusAddress; | ||
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder; | ||
import org.freedesktop.dbus.connections.transports.TransportBuilder; | ||
import org.freedesktop.dbus.test.AbstractBaseTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test case to verify that shared connections do not block reconnect. | ||
* When a client uses shared connections and gets disconnected because | ||
* the daemon disappears, the shared connection should no longer be used. | ||
* Instead this broken connection should be cleaned from the internal connection map. | ||
*/ | ||
public class Issue244Test extends AbstractBaseTest { | ||
|
||
@Test | ||
public void testSharedConnection() { | ||
String busType = TransportBuilder.getRegisteredBusTypes().get(0); | ||
String addr = TransportBuilder.createDynamicSession(busType, false); | ||
BusAddress clientAddress = BusAddress.of(addr); | ||
BusAddress serverAddress = BusAddress.of(addr).getListenerAddress(); | ||
|
||
logger.info("Creating {} based DBus daemon on address {}", busType, serverAddress); | ||
|
||
try (var edbus = new EmbeddedDBusDaemon(serverAddress)) { | ||
edbus.startInBackgroundAndWait(MAX_WAIT); | ||
try (var con = DBusConnectionBuilder.forAddress(clientAddress).build()) { | ||
assertTrue(con.isConnected(), "First connection attempt must work"); | ||
edbus.close(); // terminate daemon to enforce disconnect | ||
Thread.sleep(1000L); | ||
assertFalse(con.isConnected(), "No connection expected after first disconnect"); // no connection without daeon | ||
} | ||
|
||
// restart daemon and retry | ||
edbus.startInBackgroundAndWait(MAX_WAIT); | ||
try (var con = DBusConnectionBuilder.forAddress(clientAddress).build()) { | ||
assertTrue(con.isConnected(), "Second connection attempt must work"); | ||
edbus.close(); // terminate daemon to enforce disconnect | ||
Thread.sleep(1000L); | ||
assertFalse(con.isConnected(), "No connection expected after second disconnect"); // no connection without daeon | ||
} | ||
|
||
} catch (Exception _ex) { | ||
fail("No exception expected", _ex); | ||
} | ||
|
||
} | ||
} |