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

Disconnecting USB device causes Java to exit with 2.5 #1492

Closed
robnielsen opened this issue May 22, 2020 · 14 comments
Closed

Disconnecting USB device causes Java to exit with 2.5 #1492

robnielsen opened this issue May 22, 2020 · 14 comments
Labels
external bug A problem or unintended behavior of an external library

Comments

@robnielsen
Copy link

I'm trying improve how the Insteon binding handles reconnects. During my testing of the PLM which uses a USB port, Java exits with no error in the following situation on Linux

  1. disconnect a working USB device, this causes a IOException to get thrown
  2. close the IO streams associated with the device
  3. open the USB device

This causes Java to exit in gnu.io.CommPortIdentifier.open():

throw new gnu.io.PortInUseException(
	native_psmisc_report_owner(PortName));

With nrjavaserial-3.14.0.jar, this is line 474 in CommPortIdentifier.java.

It appears that Java is crashing while trying to call the native method native_psmisc_report_owner.

This appears to be the same as https://code.google.com/archive/p/nrjavaserial/issues/27

@wborn
Copy link
Member

wborn commented May 22, 2020

I've created NeuronRobotics/nrjavaserial#180 for this recently.

@wborn wborn added the external bug A problem or unintended behavior of an external library label May 22, 2020
@robnielsen
Copy link
Author

@wborn, this might be different. Here's the code:

SerialPortIdentifier spi = serialPortManager.getIdentifier(devName);
if (spi == null) {
    logger.warn("{} is not a valid serial port.", devName);
    return false;
}

port = spi.open(appName, 1000);

I created NeuronRobotics/nrjavaserial#181 for this issue.

@wborn
Copy link
Member

wborn commented May 22, 2020

Did you also test using nrjavaserial 5.1+?
It has several fixes when USB devices are unplugged.

@wborn
Copy link
Member

wborn commented May 22, 2020

I've created a reversioned nrjavaserial 5.1.1 bundle that can also be easily used with OH 2.5.x.
See: openhab/org.openhab.binding.zwave#1332 (comment).

@robnielsen
Copy link
Author

@wborn, I gave 5.1.1 a try and it still crashes. I renamed the old library by appending .old:

$ ls -l runtime/system/org/openhab/nrjavaserial/3.15.0.OH2/*
-rw-r--r-- 1 rob rob 728329 May 22 08:17 runtime/system/org/openhab/nrjavaserial/3.15.0.OH2/nrjavaserial-3.15.0.OH2.jar
-rw-r--r-- 1 rob rob 748907 May 20 05:28 runtime/system/org/openhab/nrjavaserial/3.15.0.OH2/nrjavaserial-3.15.0.OH2.jar.old
$ unzip -l runtime/system/org/openhab/nrjavaserial/3.15.0.OH2/nrjavaserial-3.15.0.OH2.jar
Archive:  runtime/system/org/openhab/nrjavaserial/3.15.0.OH2/nrjavaserial-3.15.0.OH2.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2020-05-09 13:09   META-INF/
     1237  2020-05-15 01:31   META-INF/MANIFEST.MF
        0  2020-05-09 13:09   com/

@robnielsen
Copy link
Author

This should be fixed in nrjavaserial 5.2.0.

@wborn
Copy link
Member

wborn commented May 22, 2020

It doesn't seem to fix the other issue NeuronRobotics/nrjavaserial#180.
At least the whole JVM doesn't exit now which is certainly an improvement. 😉

@robnielsen
Copy link
Author

@wborn, let me know if you have a reversioned bundle like you have above for 5.1.1. If so, I'll give it a try.

@wborn
Copy link
Member

wborn commented May 22, 2020

I've reversioned 5.2.1 in this nrjavaserial-3.15.0.OH2.jar.

@robnielsen
Copy link
Author

This is fixed with 5.2.1

@wborn
Copy link
Member

wborn commented May 23, 2020

That's certainly nice! There's still NeuronRobotics/nrjavaserial#111 that may cause the library fail to reconnect after the device has been unplugged for a while and you then reconnect it. 🙁

@robnielsen
Copy link
Author

@wborn,
Java is no longer crashing, but the library still isn't working correctly either. On disconnect, the following code:

SerialPortIdentifier spi = serialPortManager.getIdentifier(devName);
if (spi == null) {
    logger.warn("{} is not a valid serial port.", devName);
    return false;
}

spi is false. It should be true.

@robnielsen
Copy link
Author

I tried calling serialPortManager.getIdentifier(devName) once, and started to get the PortInUseException. But this created a new issue, the PortInUseException continued to get thrown after the device is plugged back in.

@wborn
Copy link
Member

wborn commented May 7, 2021

Let's close this since the original issue is fixed with nrjavaserial 5.2.1.

If you have more nrjavaserial related issues, please create issues for these in the nrjavaserial issue tracker. That way they will be fixed sooner because the nrjavaserial maintainers don't look for issues in their library in this tracker. 😉

@wborn wborn closed this as completed May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external bug A problem or unintended behavior of an external library
Projects
None yet
Development

No branches or pull requests

2 participants