dolphin-platform
dolphin-platform copied to clipboard
wrong exception message on disconnect in dp legacy code
DP 0.19.0
In our FX-Client I often get messages like this one here:
ERROR com.canoo.dp.impl.platform.core.SimpleUncaughtExceptionHandler - Unhandled error in Dolphin Platform background thread Dolphin-Platform-Background-Thread-5
java.lang.IllegalStateException: Can not call disconnect on a disconnected connection
at com.canoo.dp.impl.client.legacy.communication.AbstractClientConnector.disconnect(AbstractClientConnector.java:275)
at com.canoo.dp.impl.client.DolphinPlatformHttpClientConnector.disconnect(DolphinPlatformHttpClientConnector.java:96)
at com.canoo.dp.impl.client.legacy.communication.AbstractClientConnector.handleError(AbstractClientConnector.java:81)
at com.canoo.dp.impl.client.legacy.communication.AbstractClientConnector.access$200(AbstractClientConnector.java:38)
at com.canoo.dp.impl.client.legacy.communication.AbstractClientConnector$5.run(AbstractClientConnector.java:241)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Looking at the code I see in AbstractClientConnector:
private void handleError(final Exception exception) {
Objects.requireNonNull(exception);
disconnect();
uiExecutor.execute(new Runnable() {
@Override
public void run() {
connectionFlagForUiExecutor = false;
if (exception instanceof DolphinRemotingException) {
remotingExceptionHandler.handle((DolphinRemotingException) exception);
} else {
remotingExceptionHandler.handle(new DolphinRemotingException("internal remoting error", exception));
}
}
});
}
which tells me, we use the uiExecutor to report the error. But in disconnect we have this:
public void disconnect() {
if (!connectedFlag.get()) {
throw new IllegalStateException("Can not call disconnect on a disconnected connection");
}
connectedFlag.set(false);
uiExecutor.execute(new Runnable() {
@Override
public void run() {
connectionFlagForUiExecutor = false;
}
});
}
If we now have an exception because of a connectivity issue and we are actually no longer connected to dolphin, then instead of seeing the exception that caused the disconnect or that is thrown because of the disconnect I will see this IllegalStateException and the remotingExceptionHandler in not get a chance to handle the error.