Skip to content

Commit

Permalink
Improve handling of worker creation errors (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Oct 17, 2024
1 parent 88df4bc commit bbdabf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/controllers/ExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ export class ExtensionController implements Disposable {
this._config,
this._coreCredentialsCache,
this._dhcServiceFactory,
this._dheServiceCache
this._dheServiceCache,
this._outputChannel,
this._toaster
);
this._context.subscriptions.push(this._serverManager);

Expand Down
19 changes: 16 additions & 3 deletions src/services/ServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
WorkerURL,
Lazy,
UniqueID,
IToastService,
} from '../types';
import {
getInitialServerStates,
Expand All @@ -39,14 +40,18 @@ export class ServerManager implements IServerManager {
configService: IConfigService,
coreCredentialsCache: URLMap<Lazy<DhcType.LoginCredentials>>,
dhcServiceFactory: IDhServiceFactory,
dheServiceCache: IAsyncCacheService<URL, IDheService>
dheServiceCache: IAsyncCacheService<URL, IDheService>,
outputChannel: vscode.OutputChannel,
toaster: IToastService
) {
this._configService = configService;
this._connectionMap = new URLMap<ConnectionState>();
this._coreCredentialsCache = coreCredentialsCache;
this._dhcServiceFactory = dhcServiceFactory;
this._dheServiceCache = dheServiceCache;
this._outputChannel = outputChannel;
this._serverMap = new URLMap<ServerState>();
this._toaster = toaster;
this._uriConnectionsMap = new URIMap<ConnectionState>();
this._workerURLToServerURLMap = new URLMap<URL>();

Expand All @@ -62,6 +67,8 @@ export class ServerManager implements IServerManager {
>;
private readonly _dhcServiceFactory: IDhServiceFactory;
private readonly _dheServiceCache: IAsyncCacheService<URL, IDheService>;
private readonly _outputChannel: vscode.OutputChannel;
private readonly _toaster: IToastService;
private readonly _uriConnectionsMap: URIMap<ConnectionState>;
private readonly _workerURLToServerURLMap: URLMap<URL>;
private _serverMap: URLMap<ServerState>;
Expand Down Expand Up @@ -187,16 +194,22 @@ export class ServerManager implements IServerManager {
try {
workerInfo = await dheService.createWorker(tagId, workerConsoleType);

// If connection was closed by user before worker finished creating,
// dispose of the worker
// If the worker finished creating, but there is no placeholder connection,
// this indicates that the user cancelled the creation before it was ready.
// In this case, dispose of the worker.
if (!this._connectionMap.has(placeholderUrl)) {
dheService.deleteWorker(workerInfo.grpcUrl);
this._onDidUpdate.fire();
return null;
}
} catch (err) {
logger.error(err);
const msg = 'Failed to create worker.';
this._outputChannel.appendLine(msg);
this._toaster.error(msg);

this.updateConnectionCount(serverUrl, -1);
this._connectionMap.delete(placeholderUrl);
return null;
}

Expand Down

0 comments on commit bbdabf8

Please sign in to comment.