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

Conversation

devnaumov
Copy link
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
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.

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

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

@Wroud Wroud merged commit 768f3bc into devel Jan 11, 2024
4 checks passed
@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