Skip to content

Commit 7e28b07

Browse files
committed
refactor(livesync): close socket when application process is killed
1 parent 85c29fc commit 7e28b07

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

test-app/app/src/debug/java/com/tns/NativeScriptSyncService.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public NativeScriptSyncService(Runtime runtime, Logger logger, Context context)
3030
}
3131

3232
private class LocalServerSocketThread implements Runnable {
33+
3334
private volatile boolean running;
3435
private final String name;
3536

@@ -63,6 +64,11 @@ public void run() {
6364
e.printStackTrace();
6465
}
6566
}
67+
68+
@Override
69+
protected void finalize() throws Throwable {
70+
this.serverSocket.close();
71+
}
6672
}
6773

6874
public void startServer() {
@@ -148,12 +154,6 @@ public void run() {
148154
logger.write(String.format("Error while LiveSyncing: %s", e.toString()));
149155
e.printStackTrace();
150156
exceptionWhileLivesyncing = true;
151-
} finally {
152-
try {
153-
socket.close();
154-
} catch (IOException e) {
155-
e.printStackTrace();
156-
}
157157
}
158158

159159
if (!exceptionWhileLivesyncing) {
@@ -308,5 +308,10 @@ private byte[] readNextBytes(int size) throws IOException {
308308
return buffer;
309309
}
310310

311+
@Override
312+
protected void finalize() throws Throwable {
313+
this.socket.close();
314+
}
315+
311316
}
312317
}

0 commit comments

Comments
 (0)