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

CB-4468 iterate over copy of state array #2278

Merged
merged 2 commits into from
Jan 11, 2024
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 @@ -65,7 +65,9 @@ export class SqlResultTabsService {
}

removeResultTabs(state: ISqlEditorTabState, excludedTabIds?: string[]): void {
for (const tab of state.tabs) {
const tabs = state.tabs.slice();

for (const tab of tabs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to do the same thing for this function below. Just to avoid similar bug in future when the logic gets a bit more complex:

async canCloseResultTabs(state: ISqlEditorTabState): Promise<boolean> {
    const tabs = state.tabs.slice();
    for (const tab of tabs) {
      const canClose = await this.sqlQueryResultService.canCloseResultTab(state, tab.id);

      if (!canClose) {
        return false;
      }
    }

    return true;
  }

Copy link
Member

Choose a reason for hiding this comment

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

This one is a bit tricky because of asynchronous.
Imagine a case when we clicked to close all tabs

  1. First, we will check that every tab can be closed
  2. for example, let's assume that one tab can close fn took more than a 1s
  3. we can try to close any other tab at this moment

This will create a case when a tab in the tabs array is closed.

So, in general, canCloseResultTabs is not affected by this bug, but I described another case before. So, we probably need to track such operations and disable related actions during transactions.

if (excludedTabIds?.includes(tab.id)) {
continue;
}
Expand Down
Loading