Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix https://github.com/zerotier/libzt/issues/242 #243

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ void Events::sendToUser(zts_event_msg_t* msg)
id = msg->peer ? msg->peer->peer_id : 0;
}
env->CallVoidMethod(javaCbObjRef, javaCbMethodId, id, msg->event_code);

jvm->DetachCurrentThread();
}
#endif // ZTS_ENABLE_JAVA
#ifdef ZTS_ENABLE_PINVOKE
Expand Down
77 changes: 77 additions & 0 deletions test/ExitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import com.zerotier.sockets.*;

//
// Test for:
// Java process does not exit after finishing libzt work
// https://github.com/zerotier/libzt/issues/242
//
// Run and ensure that process exits
//
public class ExitTest {

public static void main(String[] args) throws InterruptedException {

long networkId = Long.parseUnsignedLong("ebe7fbd445e76ac6", 16);
String storagePath = "exittest_storage";

ZeroTierNode node = new ZeroTierNode();
node.initFromStorage(storagePath);
node.initSetEventHandler(new ZeroTierEventListener() {
@Override
public void onZeroTierEvent(long l, int eventCode) {
if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_UP) {
System.err.println("ZTS_EVENT_NODE_UP");
}
if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_ONLINE) {
System.err.println("ZTS_EVENT_NODE_ONLINE");
}
if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_OFFLINE) {
System.err.println("ZTS_EVENT_NODE_OFFLINE");
}
if (eventCode == ZeroTierNative.ZTS_EVENT_NODE_DOWN) {
System.err.println("ZTS_EVENT_NODE_DOWN");
}
if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_READY_IP4) {
System.err.println("ZTS_EVENT_NETWORK_READY_IP4");
}
if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_READY_IP6) {
System.err.println("ZTS_EVENT_NETWORK_READY_IP6");
}
if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_DOWN) {
System.err.println("ZTS_EVENT_NETWORK_DOWN");
}
if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_OK) {
System.err.println("ZTS_EVENT_NETWORK_OK");
}
if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_ACCESS_DENIED) {
System.err.println("ZTS_EVENT_NETWORK_ACCESS_DENIED");
}
if (eventCode == ZeroTierNative.ZTS_EVENT_NETWORK_NOT_FOUND) {
System.err.println("ZTS_EVENT_NETWORK_NOT_FOUND");
}
}
});

System.err.println("start");
node.start();

System.err.println("delay until online");
while (!node.isOnline()) {
ZeroTierNative.zts_util_delay(50);
}
System.err.println("done delaying");

System.out.println("join");
node.join(networkId);

System.out.println("delaying until transport ready");
while (! node.isNetworkTransportReady(networkId)) {
ZeroTierNative.zts_util_delay(50);
}

System.err.println("stop");
node.stop();

System.err.println("exiting");
}
}