mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 13:16:44 +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 org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.ConnectException;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.StandardProtocolFamily;
|
import java.net.StandardProtocolFamily;
|
||||||
import java.net.UnixDomainSocketAddress;
|
import java.net.UnixDomainSocketAddress;
|
||||||
|
@ -48,7 +49,6 @@ public abstract class Instance {
|
||||||
|
|
||||||
if(!Files.exists(lockFile)) {
|
if(!Files.exists(lockFile)) {
|
||||||
startServer(lockFile);
|
startServer(lockFile);
|
||||||
createSymlink(lockFile);
|
|
||||||
} else {
|
} else {
|
||||||
doClient(lockFile);
|
doClient(lockFile);
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,8 @@ public abstract class Instance {
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
thread.setName("SparrowInstanceListener");
|
thread.setName("SparrowInstanceListener");
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
|
createSymlink(lockFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doClient(Path lockFile) throws InstanceException {
|
private void doClient(Path lockFile) throws InstanceException {
|
||||||
|
@ -115,6 +117,13 @@ public abstract class Instance {
|
||||||
beforeExit();
|
beforeExit();
|
||||||
System.exit(0);
|
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) {
|
} catch(Exception e) {
|
||||||
throw new InstanceException("Could not open client connection to existing instance", e);
|
throw new InstanceException("Could not open client connection to existing instance", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue