diff --git a/src/main/java/com/sparrowwallet/sparrow/instance/Instance.java b/src/main/java/com/sparrowwallet/sparrow/instance/Instance.java index 9247df6b..b667952d 100644 --- a/src/main/java/com/sparrowwallet/sparrow/instance/Instance.java +++ b/src/main/java/com/sparrowwallet/sparrow/instance/Instance.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import java.net.ConnectException; import java.net.SocketException; import java.net.StandardProtocolFamily; import java.net.UnixDomainSocketAddress; @@ -48,7 +49,6 @@ public abstract class Instance { if(!Files.exists(lockFile)) { startServer(lockFile); - createSymlink(lockFile); } else { doClient(lockFile); } @@ -102,6 +102,8 @@ public abstract class Instance { thread.setDaemon(true); thread.setName("SparrowInstanceListener"); thread.start(); + + createSymlink(lockFile); } private void doClient(Path lockFile) throws InstanceException { @@ -115,6 +117,13 @@ public abstract class Instance { beforeExit(); System.exit(0); } + } catch(ConnectException e) { + try { + Files.deleteIfExists(lockFile); + startServer(lockFile); + } catch(IOException ex) { + throw new InstanceException("Could not delete lock file from previous instance", e); + } } catch(Exception e) { throw new InstanceException("Could not open client connection to existing instance", e); }