Skip to content

Commit 52aa231

Browse files
author
Liza K
committed
Don't close sessions automatically, warn instead
1 parent c8294b6 commit 52aa231

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

src/plugins/data/public/plugin.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,6 @@ export class DataPublicPlugin
210210
storage: this.storage,
211211
});
212212

213-
/*
214-
Clear any open sessions upon navigation to make sure they are not used mistakenly by
215-
another application.
216-
*/
217-
core.application.currentAppId$.subscribe(() => {
218-
search.session.clear();
219-
});
220-
221213
return {
222214
...dataServices,
223215
ui: {

src/plugins/data/public/search/search_service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
7676
): ISearchSetup {
7777
this.usageCollector = createUsageCollector(getStartServices, usageCollection);
7878

79-
this.sessionService = new SessionService();
79+
this.sessionService = new SessionService(this.initializerContext, getStartServices);
8080
/**
8181
* A global object that intercepts all searches and provides convenience methods for cancelling
8282
* all pending search requests, as well as getting the number of pending search requests.

src/plugins/data/public/search/session_service.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,46 @@
1818
*/
1919

2020
import uuid from 'uuid';
21-
import { Subject } from 'rxjs';
21+
import { Subject, Subscription } from 'rxjs';
22+
import { PluginInitializerContext, StartServicesAccessor } from 'kibana/public';
2223
import { ISessionService } from '../../common/search';
24+
import { ConfigSchema } from '../../config';
2325

2426
export class SessionService implements ISessionService {
2527
private sessionId?: string;
2628
private session$: Subject<string | undefined> = new Subject();
29+
private appChangeSubscription$?: Subscription;
30+
private curApp?: string;
31+
32+
constructor(
33+
initializerContext: PluginInitializerContext<ConfigSchema>,
34+
getStartServices: StartServicesAccessor
35+
) {
36+
/*
37+
Make sure that apps don't leave sessions open.
38+
*/
39+
getStartServices().then(([coreStart]) => {
40+
this.appChangeSubscription$ = coreStart.application.currentAppId$.subscribe((appName) => {
41+
if (this.sessionId) {
42+
const message = `Application '${this.curApp}' had an open session while navigating`;
43+
if (initializerContext.env.mode.dev) {
44+
// TODO: This setTimeout is necessary due to a race condition while navigating.
45+
setTimeout(() => {
46+
coreStart.fatalErrors.add(message);
47+
}, 100);
48+
} else {
49+
// eslint-disable-next-line no-console
50+
console.warn(message);
51+
}
52+
}
53+
this.curApp = appName;
54+
});
55+
});
56+
}
57+
58+
public destroy() {
59+
this.appChangeSubscription$?.unsubscribe();
60+
}
2761

2862
public getSessionId() {
2963
return this.sessionId;

src/plugins/discover/public/application/angular/discover.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise
332332
if (abortController) abortController.abort();
333333
savedSearch.destroy();
334334
subscriptions.unsubscribe();
335+
data.search.session.clear();
335336
appStateUnsubscribe();
336337
stopStateSync();
337338
stopSyncingGlobalStateWithUrl();

0 commit comments

Comments
 (0)