Upgrading module crashes gateway when devices present

We have implemented a custom module based on the Abstract Tag Driver example.

If there are any devices configured with the module and I try to update the module then the gateway crashes.

If there aren’t any devices using this module then I can update it with no issues.

How do I debug this behavior?

Ignition 7.9.12

You can go really old school and just stare at your code until you figure it out.

Or go kinda old school and add a bunch of print statements for debugging.

Or you can try to set up remote debugging: https://docs.inductiveautomation.com/display/SE/Debugging+in+IntelliJ

Mr. Herron, thank you for encouraging me to empower myself. IntelliJ with remote debugging is excellent.

My problem had to do with loading and unloading a dll.

I was following this suggestion here

If I stepped through the execution with the debuger everything would be fine. Does this imply that the dll load is async and one should wait some time before trying to reference it?

I’ve opted for catching the “UnsatisfiedLinkError” during the ModuleHook.setup() instead of unloading the library during ModuleHook.shutdown().

Hmm, no, that has not been my experience.

Using a native library in your module is opening a can of worms. Java 11+ should unload the library once the ClassLoader that loaded it has been garbage collected but this can take some time and you don’t know when it has happened.

In the past we’ve simply considered modules that load a native library to be “one and done” - they can’t be restarted - but there is not a way to actually prevent that from happening.

Bingo. I fought this loading OpenCV for quite a bit. I peeked at the disassembly of IA’s JNI resource loading helper to discover that you can get around the problem with a temporary file and unique file name. As long as it is a new classloader, which it will be in a module context, it won’t clash.

Are you talking about the NativeLibraryManager thing?

Yes. The one that takes a jar resource IIRC. I couldn’t use that directly, since I was loading from disk.