fix connection deadlock, speed up reconnect (#3936)

This commit is contained in:
Matthew Kennedy 2022-02-15 19:35:04 -08:00 committed by GitHub
parent b1430e88f4
commit 45acca32f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 18 deletions

View File

@ -160,8 +160,10 @@ public class IoUtil {
linkManager.getEngineState().registerStringValueAction(Fields.PROTOCOL_OUTPIN, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
linkManager.getEngineState().registerStringValueAction(AverageAnglesUtil.KEY, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
CountDownLatch connected = linkManager.connect(port);
if (connected.getCount() > 0)
try {
linkManager.connect(port).await(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new IllegalStateException("Not connected in time");
}
}
}

View File

@ -14,7 +14,7 @@ public interface Timeouts {
int BINARY_IO_TIMEOUT = 5 * SECOND;
int READ_IMAGE_TIMEOUT = 60 * SECOND;
int CONNECTION_RESTART_DELAY = BINARY_IO_TIMEOUT;
int CONNECTION_RESTART_DELAY = 1 * SECOND;
int CMD_TIMEOUT = 20 * SECOND;
int SET_ENGINE_TIMEOUT = 60 * SECOND;

View File

@ -89,6 +89,7 @@ public class LinkManager implements Closeable {
@NotNull
public CountDownLatch connect(String port) {
final CountDownLatch connected = new CountDownLatch(1);
startAndConnect(port, new ConnectionStateListener() {
@Override
public void onConnectionFailed() {
@ -101,11 +102,7 @@ public class LinkManager implements Closeable {
connected.countDown();
}
});
try {
connected.await(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
return connected;
}

View File

@ -7,6 +7,7 @@ import com.rusefi.io.LinkManager;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class SerialSandbox {
public static void main(String[] args) {
@ -25,8 +26,11 @@ public class SerialSandbox {
LinkManager linkManager = new LinkManager()
.setNeedPullText(textPull) // todo: open issue #2
.setNeedPullLiveData(true);
CountDownLatch connected = linkManager.connect(port);
if (connected.getCount() > 0)
try {
linkManager.connect(port).await(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new IllegalStateException("Not connected in time");
}
}
}

View File

@ -91,14 +91,6 @@ public class ConsoleUI {
if (LinkManager.isLogViewerMode(port))
tabbedPane.addTab("Log Viewer", new LogViewer(uiContext, engineSnifferPanel));
// TODO: this is a race if the ECU is slow to connect
new ConnectionWatchdog(Timeouts.CONNECTION_RESTART_DELAY, () -> {
uiContext.getLinkManager().execute(() -> {
log.info("ConnectionWatchdog.reconnectTimer restarting: " + Timeouts.CONNECTION_RESTART_DELAY);
linkManager.restart();
});
}).start();
uiContext.DetachedRepositoryINSTANCE.init(getConfig().getRoot().getChild("detached"));
uiContext.DetachedRepositoryINSTANCE.load();
if (!linkManager.isLogViewer())

View File

@ -84,6 +84,13 @@ public class MainFrame {
@Override
public void onConnectionEstablished() {
new ConnectionWatchdog(Timeouts.CONNECTION_RESTART_DELAY, () -> {
linkManager.execute(() -> {
log.info("ConnectionWatchdog.reconnectTimer restarting: " + Timeouts.CONNECTION_RESTART_DELAY);
linkManager.restart();
});
}).start();
tabbedPane.settingsTab.showContent();
tabbedPane.logsManager.showContent();
tabbedPane.fuelTunePane.showContent();