-
Notifications
You must be signed in to change notification settings - Fork 57
Improve management of web sessions when connection changes #1808
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
Open
isc-bsaviano
wants to merge
2
commits into
intersystems-community:master
Choose a base branch
from
isc-bsaviano:fix-1805
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−72
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,7 @@ import { ObjectScriptRoutineSymbolProvider } from "./providers/ObjectScriptRouti | |
| import { ObjectScriptCodeLensProvider } from "./providers/ObjectScriptCodeLensProvider"; | ||
| import { XmlContentProvider } from "./providers/XmlContentProvider"; | ||
|
|
||
| import { AtelierAPI } from "./api"; | ||
| import { AtelierAPI, cookiesMap, logoutOfSessions } from "./api"; | ||
| import { ObjectScriptDebugAdapterDescriptorFactory } from "./debug/debugAdapterFactory"; | ||
| import { ObjectScriptConfigurationProvider } from "./debug/debugConfProvider"; | ||
| import { ProjectsExplorerProvider } from "./explorer/projectsExplorer"; | ||
|
|
@@ -340,20 +340,16 @@ export function getResolvedConnectionSpec(key: string, dflt: any): any { | |
| /** The `api.serverId`s of all servers that are known to be inactive */ | ||
| export const inactiveServerIds: Set<string> = new Set(); | ||
|
|
||
| export async function checkConnection( | ||
| clearCookies = false, | ||
| uri?: vscode.Uri, | ||
| triggerRefreshes?: boolean | ||
| ): Promise<void> { | ||
| export async function checkConnection(clearState = false, uri?: vscode.Uri, triggerRefreshes?: boolean): Promise<void> { | ||
| // Do nothing if already checking the connection | ||
| if (checkingConnection) { | ||
| return; | ||
| } | ||
|
|
||
| const { apiTarget, configName } = connectionTarget(uri); | ||
| const wsKey = configName.toLowerCase(); | ||
| if (clearCookies) { | ||
| /// clean-up cached values | ||
| if (clearState) { | ||
| // clean-up cached values | ||
| await workspaceState.update(wsKey + ":host", undefined); | ||
| await workspaceState.update(wsKey + ":port", undefined); | ||
| await workspaceState.update(wsKey + ":superserverPort", undefined); | ||
|
|
@@ -422,10 +418,6 @@ export async function checkConnection( | |
| } | ||
| } | ||
|
|
||
| if (clearCookies) { | ||
| api.clearCookies(); | ||
| } | ||
|
|
||
| // Before recreating the api object (in case something has updated connection details since we last fetched them?) | ||
| // if this is an external server, remove it from the inactive list because its presence there would block the reconnect that we want to be attempting | ||
| if (api.externalServer) { | ||
|
|
@@ -1521,38 +1513,44 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> { | |
| supportsMultipleEditorsPerDocument: false, | ||
| }), | ||
| vscode.workspace.onDidChangeConfiguration(async ({ affectsConfiguration }) => { | ||
| if (affectsConfiguration("objectscript.conn") || affectsConfiguration("intersystems.servers")) { | ||
| if (affectsConfiguration("intersystems.servers")) { | ||
| // Gather the server names previously resolved | ||
| const resolvedServers: string[] = []; | ||
| resolvedConnSpecs.forEach((v, k) => resolvedServers.push(k)); | ||
| // Clear the cache | ||
| resolvedConnSpecs.clear(); | ||
| // Resolve them again, sequentially in case user needs to be prompted for credentials | ||
| for await (const serverName of resolvedServers) { | ||
| await resolveConnectionSpec(serverName); | ||
| } | ||
| } | ||
| // Check connections sequentially for each workspace folder | ||
| let refreshFilesExplorer = false; | ||
| for await (const folder of vscode.workspace.workspaceFolders ?? []) { | ||
| if (schemas.includes(folder.uri.scheme)) { | ||
| refreshFilesExplorer = true; | ||
| } | ||
| try { | ||
| await checkConnection(true, folder.uri, true); | ||
| } catch (_) { | ||
| continue; | ||
| } | ||
| // Loop through all ws folder connections and see if any changed | ||
| // Find all "sessions" that are new or orphaned. | ||
| // For new ones, establish a connection? | ||
| // For orphans, logout and clear the cookies. | ||
| let refreshFilesExplorer = false; | ||
| const newConnections: Set<string> = new Set(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| const affectedWsFolders: vscode.WorkspaceFolder[] = []; | ||
| for (const wsFolder of vscode.workspace.workspaceFolders ?? []) { | ||
| const api = new AtelierAPI(wsFolder.uri); | ||
| newConnections.add(api.mapKey()); | ||
| const { serverName } = api.config; | ||
| if ( | ||
| (notIsfs(wsFolder.uri) && affectsConfiguration("objectscript.conn", wsFolder)) || | ||
| (serverName && affectsConfiguration(`intersystems.servers.${serverName}`, wsFolder)) | ||
| ) { | ||
| // Connection info changed | ||
| affectedWsFolders.push(wsFolder); | ||
| if (filesystemSchemas.includes(wsFolder.uri.scheme)) refreshFilesExplorer = true; | ||
| } | ||
| explorerProvider.refresh(); | ||
| projectsExplorerProvider.refresh(); | ||
| if (refreshFilesExplorer) { | ||
| // This unavoidably switches to the File Explorer view, so only do it if isfs folders were found | ||
| vscode.commands.executeCommand("workbench.files.action.refreshFilesExplorer"); | ||
| } | ||
| // Log out of any sessions that are orphaned | ||
| logoutOfSessions(Array.from(cookiesMap.keys()).filter((k) => !newConnections.has(k))); | ||
| // Update the connection info for affected workspace folders | ||
| // This should create new CSP sessions if needed | ||
| for (const wsFolder of affectedWsFolders) { | ||
| try { | ||
| await checkConnection(true, wsFolder.uri, true); | ||
| } catch { | ||
| // Errors are handled by checkConnection() | ||
| } | ||
| updateWebAndAbstractDocsCaches(vscode.workspace.workspaceFolders); | ||
| } | ||
| explorerProvider.refresh(); | ||
| projectsExplorerProvider.refresh(); | ||
| if (refreshFilesExplorer) { | ||
| // This unavoidably switches to the File Explorer view, so only do it if isfs folders were found | ||
| vscode.commands.executeCommand("workbench.files.action.refreshFilesExplorer"); | ||
| } | ||
| updateWebAndAbstractDocsCaches(affectedWsFolders); | ||
| if (affectsConfiguration("objectscript.commentToken")) { | ||
| // Update the language configuration for "objectscript" and "objectscript-macros" | ||
| macLangConf?.dispose(); | ||
|
|
@@ -2037,24 +2035,5 @@ export async function deactivate(): Promise<void> { | |
| intLangConf?.dispose(); | ||
| disposeDocumentIndex(); | ||
| // Log out of all CSP sessions | ||
| const loggedOut: Set<string> = new Set(); | ||
| const promises: Promise<any>[] = []; | ||
| for (const f of vscode.workspace.workspaceFolders ?? []) { | ||
| const api = new AtelierAPI(f.uri); | ||
| if (!api.active || !api.cookies.length) continue; | ||
| const sessionCookie = api.cookies.find((c) => c.startsWith("CSPSESSIONID-")); | ||
| if (!sessionCookie || loggedOut.has(sessionCookie)) continue; | ||
| loggedOut.add(sessionCookie); | ||
| promises.push( | ||
| api.request( | ||
| 0, | ||
| "HEAD", | ||
| undefined, | ||
| undefined, | ||
| // Prefer IRISLogout for servers that support it | ||
| semver.lt(api.config.serverVersion, "2018.2.0") ? { CacheLogout: "end" } : { IRISLogout: "end" } | ||
| ) | ||
| ); | ||
| } | ||
| await Promise.allSettled(promises); | ||
| await logoutOfSessions(); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, thank you for this fix! It indeed fixes the problem I reported in #1805.
--
But I noticed one new problem: changes to a server in
intersystems.serversno longer take effect until I reload the window.Reproducable by:
"objectscript.outputRESTTraffic": trueto see the requests in the "ObjectScript" output.intersystems.servers, change thewebServer.portof that server to a wrong/closed port and save.On 3.8.2 the same change takes effect immediately, without a reload.
--
It looks like the old code re-read the server settings when
intersystems.serverschanged, and that part was removed in this PR. So the extension seems to keep using the old (cached) connection details until a reload. Maybe the fix needs to re-read / refresh the server spec for the changed servers again.