cancel a retrying connection attempt when testing a server to avoid resource sharing
What changed, and why it matters
This commit adds a way to stop an ongoing background server connection attempt when the user tries to test or switch to a different server. Before the change, a retrying connection could keep running in the background while a new test connection started, causing the two attempts to share or fight over the same network resources. The fix cancels the old attempt first, then starts the new one. It is a reliability/resource-cleanup improvement rather than a clear-cut security vulnerability fix.
Treat as a reliability/resource-management improvement. Review whether the shared resource (socket, proxy, Tor circuit, or whirlpool connection) could previously be left in an inconsistent state that affects confidentiality or integrity, but no immediate security patch is indicated by the diff alone.
Security signals we found
Resource contention between concurrent/retrying network connections
Potential denial-of-service or instability from overlapping connection attempts
Cleanup of background service before creating a new one
No input validation, cryptographic, or authentication changes
Evidence from the diff
The patch introduces AppServices.cancelConnection(), which sets onlineProperty to false and cancels the running connectionService if it exists and is running. ServerSettingsController.startElectrumConnection() and ServerTestDialog.startElectrumConnection() now call this method before creating a new ElectrumServer.ConnectionService. In the GUI controller, a successful cancellation also sets reconnectOnClosingProperty to true. The stated intent is to avoid resource sharing between a retrying connection and a server-test connection.
Changed components
AppServices.javaServerSettingsController.javaServerTestDialog.javaElectrumServer.ConnectionServiceInspect captured patch +16 / −0
### src/main/java/com/sparrowwallet/sparrow/AppServices.java
@@ -752,6 +752,16 @@ public static boolean isConnected() {
return onlineProperty.get() && get().connectionService != null && get().connectionService.isConnected();
}
+ public static boolean cancelConnection() {
+ if(get().connectionService != null && get().connectionService.isRunning()) {
+ onlineProperty.set(false);
+ get().connectionService.cancel();
+ return true;
+ }
+
+ return false;
+ }
+
public static BooleanProperty onlineProperty() {
return onlineProperty;
}
### src/main/java/com/sparrowwallet/sparrow/settings/ServerSettingsController.java
@@ -560,6 +560,10 @@ private void startElectrumConnection() {
connectionService.cancel();
}
+ if(AppServices.cancelConnection()) {
+ getMasterController().reconnectOnClosingProperty().set(true);
+ }
+
connectionService = new ElectrumServer.ConnectionService(false);
connectionService.setPeriod(Duration.hours(1));
connectionService.setRestartOnFailure(false);
### src/main/java/com/sparrowwallet/sparrow/terminal/settings/ServerTestDialog.java
@@ -134,6 +134,8 @@ private void startElectrumConnection() {
connectionService.cancel();
}
+ AppServices.cancelConnection();
+
connectionService = new ElectrumServer.ConnectionService(false);
connectionService.setPeriod(Duration.hours(1));
connectionService.setRestartOnFailure(false);Why this scored 26/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.