Skip to content

CB-4468 iterate over copy of state array#2278

Merged
Wroud merged 2 commits intodevelfrom
CB-4468-tabs-close-all-problem
Jan 11, 2024
Merged

CB-4468 iterate over copy of state array#2278
Wroud merged 2 commits intodevelfrom
CB-4468-tabs-close-all-problem

Conversation

@devnaumov
Copy link
Copy Markdown
Member

No description provided.

@devnaumov devnaumov self-assigned this Jan 5, 2024
for (const tab of state.tabs) {
const tabs = state.tabs.slice();

for (const tab of tabs) {
Copy link
Copy Markdown
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
Copy Markdown
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.

for (const tab of state.tabs) {
const tabs = state.tabs.slice();

for (const tab of tabs) {
Copy link
Copy Markdown
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.

@Wroud Wroud merged commit 768f3bc into devel Jan 11, 2024
@Wroud Wroud deleted the CB-4468-tabs-close-all-problem branch January 11, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants