mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
delete existing instance lock file and recreate if client connection fails
This commit is contained in:
parent
c1fc8712d5
commit
0fad93524e
1 changed files with 10 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue