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

[Data plugin] Wrong caching for Index pattern fields #87116

Merged
merged 4 commits into from
Jan 5, 2021
Merged
Changes from 1 commit
Commits
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 @@ -46,7 +46,6 @@ import { IndexPatternMissingIndices } from '../lib';
import { findByTitle } from '../utils';
import { DuplicateIndexPatternError } from '../errors';

const indexPatternCache = createIndexPatternCache();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattkime @ppisljar it looks like an issue while unifying client/server code.

This approach unacceptable for server side code. indexPatternCache variable should not declared as instance variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also I think it should be backported into 7.10, 7.11 as a security issue.

const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3;
const savedObjectType = 'index-pattern';

Expand All @@ -72,6 +71,8 @@ export class IndexPatternsService {
private fieldFormats: FieldFormatsStartCommon;
private onNotification: OnNotification;
private onError: OnError;
private indexPatternCache: ReturnType<typeof createIndexPatternCache>;

ensureDefaultIndexPattern: EnsureDefaultIndexPattern;

constructor({
Expand All @@ -93,6 +94,8 @@ export class IndexPatternsService {
uiSettings,
onRedirectNoIndexPattern
);

this.indexPatternCache = createIndexPatternCache();
}

/**
Expand Down Expand Up @@ -175,9 +178,9 @@ export class IndexPatternsService {
clearCache = (id?: string) => {
this.savedObjectsCache = null;
if (id) {
indexPatternCache.clear(id);
this.indexPatternCache.clear(id);
} else {
indexPatternCache.clearAll();
this.indexPatternCache.clearAll();
}
};

Expand Down Expand Up @@ -435,11 +438,12 @@ export class IndexPatternsService {

get = async (id: string): Promise<IndexPattern> => {
const indexPatternPromise =
indexPatternCache.get(id) || indexPatternCache.set(id, this.getSavedObjectAndInit(id));
this.indexPatternCache.get(id) ||
this.indexPatternCache.set(id, this.getSavedObjectAndInit(id));

// don't cache failed requests
indexPatternPromise.catch(() => {
indexPatternCache.clear(id);
this.indexPatternCache.clear(id);
});

return indexPatternPromise;
Expand Down Expand Up @@ -503,7 +507,7 @@ export class IndexPatternsService {
id: indexPattern.id,
});
indexPattern.id = response.id;
indexPatternCache.set(indexPattern.id, Promise.resolve(indexPattern));
this.indexPatternCache.set(indexPattern.id, Promise.resolve(indexPattern));
return indexPattern;
}

Expand Down Expand Up @@ -586,7 +590,7 @@ export class IndexPatternsService {
indexPattern.version = samePattern.version;

// Clear cache
indexPatternCache.clear(indexPattern.id!);
this.indexPatternCache.clear(indexPattern.id!);

// Try the save again
return this.updateSavedObject(indexPattern, saveAttempts, ignoreErrors);
Expand All @@ -600,7 +604,7 @@ export class IndexPatternsService {
* @param indexPatternId: Id of kibana Index Pattern to delete
*/
async delete(indexPatternId: string) {
indexPatternCache.clear(indexPatternId);
this.indexPatternCache.clear(indexPatternId);
return this.savedObjectsClient.delete('index-pattern', indexPatternId);
}
}
Expand Down