Skip to content

#1032 failing upload flag for monitor mgr #1040

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

Merged
merged 28 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d10181b
1032 failing upload flag for monitor mgr
davegarthsimpson Jun 10, 2022
eed8a69
move upload failure fix logic to frontend
davegarthsimpson Jun 13, 2022
fff6075
misc corrections
davegarthsimpson Jun 13, 2022
cc12bc0
avoid starting monitor when upload is in progress
Jun 14, 2022
209ac69
avoid starting monitor when upload is in progress
Jun 14, 2022
9585991
Merge branch '1032-uploads-failing-with-monitor-open' of https://gith…
davegarthsimpson Jun 14, 2022
48b9c4d
prevent monitor side effects on upload (WIP)
davegarthsimpson Jun 15, 2022
01604ee
send upload req after notifying mgr
davegarthsimpson Jun 15, 2022
1e7fbf1
Merge branch 'main' into 1032-uploads-failing-with-monitor-open
davegarthsimpson Jun 15, 2022
2d5dff2
dispose instead of pause on upld (code not final)
davegarthsimpson Jun 15, 2022
89e51cb
Revert "dispose instead of pause on upld (code not final)"
davegarthsimpson Jun 16, 2022
a9d968c
force wait before upload (test)
davegarthsimpson Jun 16, 2022
bd02a19
always start queued services after uplaod finishes
Jun 16, 2022
97bdb78
test cli with monitor close delay
davegarthsimpson Jun 16, 2022
a562f0c
clean up unnecessary await(s)
davegarthsimpson Jun 17, 2022
725c0fb
remove unused dependency
davegarthsimpson Jun 17, 2022
6d1e930
Merge branch 'main' into 1032-uploads-failing-with-monitor-open
davegarthsimpson Jun 17, 2022
6710f35
revert CLI to 0.23
davegarthsimpson Jun 17, 2022
5260a07
use master cli for testing, await in upload finish
davegarthsimpson Jun 17, 2022
1678da7
remove upload port from pending monitor requests
davegarthsimpson Jun 17, 2022
37f7311
fix startQueuedServices
davegarthsimpson Jun 17, 2022
99dfd4e
refinements queued monitors
davegarthsimpson Jun 17, 2022
6e264a6
clean up monitor mgr state
davegarthsimpson Jun 17, 2022
c892ce3
fix typo from prev cleanup
davegarthsimpson Jun 19, 2022
a7c8806
avoid dupl queued monitor services
davegarthsimpson Jun 19, 2022
3830ba2
variable name changes
davegarthsimpson Jun 21, 2022
fbf3fc6
Merge branch 'main' into 1032-uploads-failing-with-monitor-open
davegarthsimpson Jun 21, 2022
095bbd9
reference latest cli commit in package.json
davegarthsimpson Jun 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export class UploadSketch extends SketchContribution {
// toggle the toolbar button and menu item state.
// uploadInProgress will be set to false whether the upload fails or not
this.uploadInProgress = true;

this.onDidChangeEmitter.fire();
const sketch = await this.sketchServiceClient.currentSketch();
if (!CurrentSketch.isValid(sketch)) {
Expand All @@ -227,7 +228,7 @@ export class UploadSketch extends SketchContribution {
...boardsConfig.selectedBoard,
name: boardsConfig.selectedBoard?.name || '',
fqbn,
}
};
let options: CoreService.Upload.Options | undefined = undefined;
const sketchUri = sketch.uri;
const optimizeForDebug = this.editorMode.compileForDebug;
Expand Down Expand Up @@ -290,6 +291,7 @@ export class UploadSketch extends SketchContribution {
this.messageService.error(errorMessage);
} finally {
this.uploadInProgress = false;

this.onDidChangeEmitter.fire();
}
}
Expand Down
38 changes: 20 additions & 18 deletions arduino-ide-extension/src/node/core-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
}
}

async upload(options: CoreService.Upload.Options): Promise<void> {
await this.doUpload(
upload(options: CoreService.Upload.Options): Promise<void> {
return this.doUpload(
options,
() => new UploadRequest(),
(client, req) => client.upload(req)
Expand All @@ -123,7 +123,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
async uploadUsingProgrammer(
options: CoreService.Upload.Options
): Promise<void> {
await this.doUpload(
return this.doUpload(
options,
() => new UploadUsingProgrammerRequest(),
(client, req) => client.uploadUsingProgrammer(req),
Expand All @@ -149,7 +149,6 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {

this.uploading = true;
const { sketchUri, board, port, programmer } = options;
await this.monitorManager.notifyUploadStarted(board, port);

const sketchPath = FileUri.fsPath(sketchUri);

Expand Down Expand Up @@ -181,13 +180,16 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
req.getUserFieldsMap().set(e.name, e.value);
});

const result = responseHandler(client, req);

const uploadBuffer = new SimpleBuffer(
this.flushOutputPanelMessages.bind(this),
FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
);
try {
await this.monitorManager.notifyUploadStarted(board, port);

const result = responseHandler(client, req);

const uploadBuffer = new SimpleBuffer(
this.flushOutputPanelMessages.bind(this),
FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
);

await new Promise<void>((resolve, reject) => {
result.on('data', (resp: UploadResponse) => {
uploadBuffer.addChunk(resp.getOutStream_asU8());
Expand Down Expand Up @@ -229,7 +231,6 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
async burnBootloader(options: CoreService.Bootloader.Options): Promise<void> {
this.uploading = true;
const { board, port, programmer } = options;
await this.monitorManager.notifyUploadStarted(board, port);

await this.coreClientProvider.initialized;
const coreClient = await this.coreClient();
Expand All @@ -252,13 +253,14 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
}
burnReq.setVerify(options.verify);
burnReq.setVerbose(options.verbose);
const result = client.burnBootloader(burnReq);

const bootloaderBuffer = new SimpleBuffer(
this.flushOutputPanelMessages.bind(this),
FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
);
try {
await this.monitorManager.notifyUploadStarted(board, port);
const result = client.burnBootloader(burnReq);

const bootloaderBuffer = new SimpleBuffer(
this.flushOutputPanelMessages.bind(this),
FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
);
await new Promise<void>((resolve, reject) => {
result.on('data', (resp: BurnBootloaderResponse) => {
bootloaderBuffer.addChunk(resp.getOutStream_asU8());
Expand Down Expand Up @@ -286,7 +288,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
throw new Error(errorMessage);
} finally {
this.uploading = false;
await this.monitorManager.notifyUploadFinished(board, port);
this.monitorManager.notifyUploadFinished(board, port);
}
}

Expand Down
13 changes: 8 additions & 5 deletions arduino-ide-extension/src/node/monitor-manager-proxy-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ export class MonitorManagerProxyImpl implements MonitorManagerProxy {
if (settings) {
await this.changeMonitorSettings(board, port, settings);
}
const status = await this.manager.startMonitor(board, port);
if (status === Status.ALREADY_CONNECTED || status === Status.OK) {
// Monitor started correctly, connect it with the frontend
this.client.connect(this.manager.getWebsocketAddressPort(board, port));
}

const onFinish = (status: Status) => {
if (status === Status.ALREADY_CONNECTED || status === Status.OK) {
// Monitor started correctly, connect it with the frontend
this.client.connect(this.manager.getWebsocketAddressPort(board, port));
}
};
return this.manager.startMonitor(board, port, onFinish);
}

/**
Expand Down
80 changes: 64 additions & 16 deletions arduino-ide-extension/src/node/monitor-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ILogger } from '@theia/core';
import { inject, injectable, named } from '@theia/core/shared/inversify';
import { Board, Port, Status } from '../common/protocol';
import { Board, BoardsService, Port, Status } from '../common/protocol';
import { CoreClientAware } from './core-client-provider';
import { MonitorService } from './monitor-service';
import { MonitorServiceFactory } from './monitor-service-factory';
Expand All @@ -15,11 +15,20 @@ export const MonitorManagerName = 'monitor-manager';

@injectable()
export class MonitorManager extends CoreClientAware {
@inject(BoardsService)
protected boardsService: BoardsService;

// Map of monitor services that manage the running pluggable monitors.
// Each service handles the lifetime of one, and only one, monitor.
// If either the board or port managed changes, a new service must
// be started.
private monitorServices = new Map<MonitorID, MonitorService>();
private isUploadInProgress: boolean;

private startMonitorPendingRequests: [
[Board, Port],
(status: Status) => void
][] = [];

@inject(MonitorServiceFactory)
private monitorServiceFactory: MonitorServiceFactory;
Expand Down Expand Up @@ -56,13 +65,25 @@ export class MonitorManager extends CoreClientAware {
* @returns a Status object to know if the process has been
* started or if there have been errors.
*/
async startMonitor(board: Board, port: Port): Promise<Status> {
async startMonitor(
board: Board,
port: Port,
postStartCallback: (status: Status) => void
): Promise<void> {
const monitorID = this.monitorID(board, port);

let monitor = this.monitorServices.get(monitorID);
if (!monitor) {
monitor = this.createMonitor(board, port);
}
return await monitor.start();

if (this.isUploadInProgress) {
this.startMonitorPendingRequests.push([[board, port], postStartCallback]);
return;
}

const result = await monitor.start();
postStartCallback(result);
}

/**
Expand Down Expand Up @@ -106,6 +127,8 @@ export class MonitorManager extends CoreClientAware {
* @param port port to monitor
*/
async notifyUploadStarted(board?: Board, port?: Port): Promise<void> {
this.isUploadInProgress = true;

if (!board || !port) {
// We have no way of knowing which monitor
// to retrieve if we don't have this information.
Expand All @@ -117,8 +140,7 @@ export class MonitorManager extends CoreClientAware {
// There's no monitor running there, bail
return;
}
monitor.setUploadInProgress(true);
return await monitor.pause();
return monitor.pause();
}

/**
Expand All @@ -130,19 +152,45 @@ export class MonitorManager extends CoreClientAware {
* started or if there have been errors.
*/
async notifyUploadFinished(board?: Board, port?: Port): Promise<Status> {
if (!board || !port) {
// We have no way of knowing which monitor
// to retrieve if we don't have this information.
return Status.NOT_CONNECTED;
}
const monitorID = this.monitorID(board, port);
const monitor = this.monitorServices.get(monitorID);
if (!monitor) {
this.isUploadInProgress = false;
let status: Status = Status.NOT_CONNECTED;
// We have no way of knowing which monitor
// to retrieve if we don't have this information.
if (board && port) {
const monitorID = this.monitorID(board, port);
const monitor = this.monitorServices.get(monitorID);
// There's no monitor running there, bail
return Status.NOT_CONNECTED;
if (monitor) {
status = await monitor.start();
}
}
await this.startQueuedServices();
return status;
}

async startQueuedServices(): Promise<void> {
const queued = this.startMonitorPendingRequests;
this.startMonitorPendingRequests = [];

for (const [[board, port], onFinish] of queued) {
const boardsState = await this.boardsService.getState();
const boardIsStillOnPort = Object.keys(boardsState)
.map((connection: string) => {
const portAddress = connection.split('|')[0];
return portAddress;
})
.some((portAddress: string) => port.address === portAddress);

if (boardIsStillOnPort) {
const monitorID = this.monitorID(board, port);
const monitorService = this.monitorServices.get(monitorID);

if (monitorService) {
const result = await monitorService.start();
onFinish(result);
}
}
}
monitor.setUploadInProgress(false);
return await monitor.start();
}

/**
Expand Down
14 changes: 0 additions & 14 deletions arduino-ide-extension/src/node/monitor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class MonitorService extends CoreClientAware implements Disposable {
protected readonly onDisposeEmitter = new Emitter<void>();
readonly onDispose = this.onDisposeEmitter.event;

protected uploadInProgress = false;
protected _initialized = new Deferred<void>();
protected creating: Deferred<Status>;

Expand Down Expand Up @@ -114,10 +113,6 @@ export class MonitorService extends CoreClientAware implements Disposable {
return this._initialized.promise;
}

setUploadInProgress(status: boolean): void {
this.uploadInProgress = status;
}

getWebsocketAddressPort(): number {
return this.webSocketProvider.getAddress().port;
}
Expand Down Expand Up @@ -161,15 +156,6 @@ export class MonitorService extends CoreClientAware implements Disposable {
return this.creating.promise;
}

if (this.uploadInProgress) {
this.updateClientsSettings({
monitorUISettings: { connected: false, serialPort: this.port.address },
});

this.creating.resolve(Status.UPLOAD_IN_PROGRESS);
return this.creating.promise;
}

this.logger.info('starting monitor');

// get default monitor settings from the CLI
Expand Down