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

fix: disconnect extension when server is closed VSCODE-536 #734

Merged
merged 43 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ab84537
chore: bump minor dependencies
alenakhineika May 23, 2024
c85e84c
chore: bump more deps
alenakhineika May 23, 2024
1b00911
chore: revert ts-loader
alenakhineika May 23, 2024
38e7614
fix: update package lock
alenakhineika May 23, 2024
572c583
chore: remove npm legacy-peer-deps
alenakhineika May 24, 2024
0f8f6ce
chore: bump vscode engine and fix useEffect cleanup
alenakhineika May 24, 2024
1c5db75
fix: try to revert data service
alenakhineika May 24, 2024
518a04a
fix: try to revert some other stuff
alenakhineika May 24, 2024
7b8392b
test: debug
alenakhineika May 24, 2024
c57060a
test: move re-auth to beforeEach
alenakhineika May 24, 2024
d2bc204
test: reset reAuthCalled
alenakhineika May 24, 2024
5968cef
test: more debug
alenakhineika May 24, 2024
68c60b0
test: moreee debug
alenakhineika May 24, 2024
9756140
test: wait longer
alenakhineika May 24, 2024
74db530
test: print data service
alenakhineika May 24, 2024
14a5c9e
test: print only options
alenakhineika May 24, 2024
9f42776
test: try to move to before each
alenakhineika May 24, 2024
b6f90a4
test: try all before each
alenakhineika May 24, 2024
f828e75
test: try to skip prev test
alenakhineika May 24, 2024
c560171
test: try without catch
alenakhineika May 24, 2024
9692079
chore: revert mongodb runner
alenakhineika May 24, 2024
07efddf
test: revert test
alenakhineika May 24, 2024
f159919
test: run one
alenakhineika May 24, 2024
5137611
test: try server 8
alenakhineika May 24, 2024
7926dc3
test: try rc4
alenakhineika May 24, 2024
8d61871
test: try x
alenakhineika May 24, 2024
fa711be
test: revert
alenakhineika May 24, 2024
757b69c
test: try latest
alenakhineika May 26, 2024
ebbef7d
test: 8.1
alenakhineika May 26, 2024
869ba89
test: latest-alpha
alenakhineika May 26, 2024
3c4d7fe
Bump packages and fix errors
alenakhineika Jun 4, 2024
0bb702c
build: package lock
alenakhineika Jun 4, 2024
f8d29e1
build: freeze mongodb and bson versions
alenakhineika Jun 4, 2024
e4bde5a
build: bump vscode engine
alenakhineika Jun 4, 2024
5e7298f
chore: bump data service
alenakhineika Jun 25, 2024
c862bce
Merge remote-tracking branch 'origin/main' into bump-minor-deps
alenakhineika Jun 25, 2024
05a8a69
build: update package lock
alenakhineika Jun 25, 2024
bdcfe59
build: update package lock again
alenakhineika Jun 25, 2024
b91a858
build: bump vscode engine
alenakhineika Jun 25, 2024
c9785c8
refactor: remove sleeps
alenakhineika Jun 25, 2024
b9dd201
refactor: return sleep
alenakhineika Jun 25, 2024
093e852
test: trigger ci
alenakhineika Jun 25, 2024
c7976cf
refactor: use waitFor
alenakhineika Jun 26, 2024
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
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

14,780 changes: 7,487 additions & 7,293 deletions package-lock.json

Large diffs are not rendered by default.

106 changes: 53 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"create-vulnerability-tickets": "mongodb-sbom-tools generate-vulnerability-report --snyk-reports=.sbom/snyk-test-result.json --dependencies=.sbom/dependencies.json --create-jira-issues"
},
"engines": {
"vscode": "^1.79.1",
"vscode": "^1.90.2",
"node": ">=16.16.0",
"npm": ">=8.19.4"
},
Expand Down Expand Up @@ -1076,93 +1076,93 @@
}
},
"dependencies": {
"@babel/parser": "^7.22.6",
"@babel/traverse": "^7.23.2",
"@mongodb-js/compass-components": "^1.21.2",
"@babel/parser": "^7.24.6",
"@babel/traverse": "^7.24.6",
"@mongodb-js/compass-components": "^1.25.0",
"@mongodb-js/connection-form": "^1.22.2",
"@mongodb-js/connection-info": "^0.1.2",
"@mongodb-js/mongodb-constants": "^0.8.9",
"@mongodb-js/mongodb-constants": "^0.10.2",
"@mongosh/browser-runtime-electron": "^2.1.1",
"@mongosh/i18n": "^2.1.1",
"@mongosh/service-provider-server": "^2.1.1",
"@mongosh/shell-api": "^2.1.1",
"@segment/analytics-node": "^1.1.4",
"bson": "^6.2.0",
"@segment/analytics-node": "^1.3.0",
"bson": "^6.7.0",
"bson-transpilers": "^2.2.0",
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"debug": "^4.3.5",
"dotenv": "^16.4.5",
"lodash": "^4.17.21",
"micromatch": "^4.0.7",
"mongodb": "^6.3.0",
"mongodb-build-info": "^1.7.1",
"mongodb-cloud-info": "^2.1.0",
"mongodb-connection-string-url": "^3.0.0",
"mongodb-data-service": "^22.17.3",
"mongodb-log-writer": "^1.4.0",
"mongodb-query-parser": "^4.0.2",
"mongodb-schema": "^12.1.1",
"mongodb": "^6.7.0",
"mongodb-build-info": "^1.7.2",
"mongodb-cloud-info": "^2.1.2",
"mongodb-connection-string-url": "^3.0.1",
"mongodb-data-service": "^22.21.1",
"mongodb-log-writer": "^1.4.2",
"mongodb-query-parser": "^4.1.3",
"mongodb-schema": "^12.2.0",
"numeral": "^2.0.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"resolve-mongodb-srv": "^1.1.3",
"resolve-mongodb-srv": "^1.1.5",
"ts-log": "^2.2.5",
"uuid": "^8.3.2",
"vscode-languageclient": "^8.1.0",
"vscode-languageserver": "^8.1.0",
"vscode-languageserver-textdocument": "^1.0.10"
"vscode-languageserver-textdocument": "^1.0.11"
},
"devDependencies": {
"@babel/preset-typescript": "^7.22.5",
"@mongodb-js/oidc-mock-provider": "^0.6.10",
"@mongodb-js/oidc-plugin": "^0.3.0",
"@babel/preset-typescript": "^7.24.7",
"@mongodb-js/oidc-mock-provider": "^0.9.1",
"@mongodb-js/oidc-plugin": "^0.4.0",
"@mongodb-js/prettier-config-devtools": "^1.0.1",
"@mongodb-js/sbom-tools": "^0.5.4",
"@mongodb-js/signing-utils": "^0.3.1",
"@mongosh/service-provider-core": "^2.0.2",
"@mongodb-js/sbom-tools": "^0.7.0",
"@mongodb-js/signing-utils": "^0.3.4",
"@mongosh/service-provider-core": "^2.2.1",
"@testing-library/react": "^12.1.5",
"@types/babel__core": "^7.20.1",
"@types/babel__traverse": "^7.20.1",
"@types/chai": "^4.3.5",
"@types/debug": "^4.1.8",
"@types/babel__core": "^7.20.5",
"@types/babel__traverse": "^7.20.6",
"@types/chai": "^4.3.16",
"@types/debug": "^4.1.12",
"@types/glob": "^7.2.0",
"@types/jest": "^26.0.24",
"@types/micromatch": "^4.0.2",
"@types/micromatch": "^4.0.7",
"@types/mkdirp": "^2.0.0",
"@types/mocha": "^8.2.3",
"@types/node": "^14.18.53",
"@types/react": "^17.0.62",
"@types/react-dom": "^17.0.20",
"@types/node": "^14.18.63",
"@types/react": "^17.0.80",
"@types/react-dom": "^17.0.25",
"@types/sinon": "^9.0.11",
"@types/uuid": "^8.3.4",
"@types/vscode": "^1.79.1",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"@vscode/test-electron": "^2.3.8",
"@vscode/vsce": "^2.19.0",
"@types/vscode": "^1.90.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@vscode/test-electron": "^2.4.0",
"@vscode/vsce": "^2.29.0",
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
"autoprefixer": "^10.4.16",
"autoprefixer": "^10.4.19",
"buffer": "^6.0.3",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"chai": "^4.4.1",
"chai-as-promised": "^7.1.2",
"cross-env": "^7.0.3",
"crypto-browserify": "^3.12.0",
"depcheck": "^1.4.3",
"depcheck": "^1.4.7",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"enzyme": "^3.11.0",
"eslint": "^8.44.0",
"eslint": "^8.57.0",
"eslint-config-mongodb-js": "^5.0.3",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-mocha": "^10.4.3",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"glob": "^7.2.3",
"jest": "^26.6.3",
"jest-junit": "^12.3.0",
"jest-transform-stub": "^2.0.0",
"mkdirp": "^1.0.4",
"mocha": "^10.2.0",
"mocha-junit-reporter": "^2.2.0",
"mocha": "^10.5.1",
"mocha-junit-reporter": "^2.2.1",
"mocha-multi": "^1.1.7",
"mongodb-client-encryption": "^6.0.0",
"mongodb-runner": "^5.5.2",
"mongodb-client-encryption": "^6.0.1",
"mongodb-runner": "^5.6.2",
"node-fetch": "^2.7.0",
"node-loader": "^0.6.0",
"npm-run-all": "^4.1.5",
Expand All @@ -1175,13 +1175,13 @@
"sinon-chai": "^3.7.0",
"stream-browserify": "^3.0.0",
"ts-jest": "^26.5.6",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "^4.9.5",
"webpack": "^5.88.1",
"webpack-bundle-analyzer": "^4.9.0",
"webpack": "^5.92.1",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.9.0",
"webpack-merge": "^5.10.0",
"xvfb-maybe": "^0.2.1"
},
"precommit": [
Expand Down
57 changes: 27 additions & 30 deletions src/connectionController.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
import * as vscode from 'vscode';
import { connect, createConnectionAttempt } from 'mongodb-data-service';
import type {
Expand Down Expand Up @@ -413,8 +414,9 @@ export default class ConnectionController {
this._statusView.hideMessage();
this._connectionAttempt = null;
this._connectingConnectionId = null;
this.eventEmitter.emit(DataServiceEventTypes.CONNECTIONS_DID_CHANGE);
}

this.eventEmitter.emit(DataServiceEventTypes.CONNECTIONS_DID_CHANGE);
}

log.info('Successfully connected', { connectionId });
Expand All @@ -423,11 +425,10 @@ export default class ConnectionController {
dataService.addReauthenticationHandler(
this._reauthenticationHandler.bind(this)
);
this._activeDataService = dataService;
this.setActiveDataService(dataService);
this._currentConnectionId = connectionId;
this._connectionAttempt = null;
this._connectingConnectionId = null;
this.eventEmitter.emit(DataServiceEventTypes.CONNECTIONS_DID_CHANGE);
this.eventEmitter.emit(DataServiceEventTypes.ACTIVE_CONNECTION_CHANGED);

// Send metrics to Segment
Expand Down Expand Up @@ -466,7 +467,6 @@ export default class ConnectionController {
);

if (removeConfirmationResponse !== 'Confirm') {
await this.disconnect();
throw new Error('Reauthentication declined by user');
}
}
Expand Down Expand Up @@ -574,43 +574,38 @@ export default class ConnectionController {

this._currentConnectionId = null;
this._disconnecting = true;
this._statusView.showMessage('Disconnecting from current connection...');

this.eventEmitter.emit(DataServiceEventTypes.CONNECTIONS_DID_CHANGE);
this.eventEmitter.emit(DataServiceEventTypes.ACTIVE_CONNECTION_CHANGED);

if (!this._activeDataService) {
void vscode.window.showErrorMessage(
'Unable to disconnect: no active connection.'
);

log.error('Unable to disconnect: no active connection');
return false;
}

this._statusView.showMessage('Disconnecting from current connection...');
const originalDisconnect = this._activeDataService.disconnect.bind(this);
this._activeDataService = null;

try {
// Disconnect from the active connection.
await this._activeDataService.disconnect();
void vscode.window.showInformationMessage('MongoDB disconnected.');
this._activeDataService = null;

void vscode.commands.executeCommand(
'setContext',
'mdb.connectedToMongoDB',
false
);
void vscode.commands.executeCommand(
'setContext',
'mdb.isAtlasStreams',
false
);
await originalDisconnect();
} catch (error) {
// Show an error, however we still reset the active connection to free up the extension.
void vscode.window.showErrorMessage(
'An error occurred while disconnecting from the current connection.'
);
log.error('Unable to disconnect', error);
}

void vscode.commands.executeCommand(
'setContext',
'mdb.connectedToMongoDB',
false
);
void vscode.commands.executeCommand(
'setContext',
'mdb.isAtlasStreams',
false
);
void vscode.window.showInformationMessage('MongoDB disconnected.');

this._disconnecting = false;
this._statusView.hideMessage();

Expand All @@ -626,9 +621,7 @@ export default class ConnectionController {
}

delete this._connections[connectionId];

await this._connectionStorage.removeConnection(connectionId);

this.eventEmitter.emit(DataServiceEventTypes.CONNECTIONS_DID_CHANGE);
}

Expand Down Expand Up @@ -989,9 +982,13 @@ export default class ConnectionController {
this._connectingConnectionId = '';
}

// Exposed for testing.
setActiveDataService(newDataService: DataService): void {
this._activeDataService = newDataService;

// Disconnect the extension if the MongoDB client is closed.
this._activeDataService?.once('close', () => {
void this.disconnect();
Anemy marked this conversation as resolved.
Show resolved Hide resolved
});
}

getConnectionQuickPicks(): ConnectionQuickPicks[] {
Expand Down
4 changes: 2 additions & 2 deletions src/telemetry/connectionTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ type CloudInfo = {

async function getHostnameForConnection(
connectionStringData: ConnectionString
): Promise<string | null> {
): Promise<string | undefined> {
if (connectionStringData.isSRV) {
const uri = await resolveMongodbSrv(connectionStringData.toString()).catch(
() => null
);
if (!uri) {
return null;
return undefined;
}
connectionStringData = new ConnectionString(uri, {
looseValidation: true,
Expand Down
Loading
Loading