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

[client] Fix creating session file #3212

Merged

Conversation

csordasmarton
Copy link
Contributor

If we run multiple CodeChecker commands (login, store) which uses the same
home directory and the CodeChecker session file (~/.codechecker.session.json)
does not exist yet the following scenario is possible:

  • The first command recognizes that this file doesn't exist yet so it will open
    this file for writing.
  • Before the first command writes data to the file the second command will be run.
    It recognizes that the file exists, so it will read up the file. It expects that
    the file is a valid json file but it is empty. So the token_dict variable
    will be an empty dict, we try to get the tokens member of this empty
    dictionary (self.__tokens) which will be None, and when we will try to
    iterate over this directory (which is None in our case) the CodeChecker will
    raise an exception.

To solve this problem we will use portalocker after we opened the file to
lock it, so only one process will be able to read/write this file simultaneously.
Also we will handle the use case when this file is still empty.

@csordasmarton csordasmarton added CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands bugfix 🔨 labels Feb 24, 2021
@csordasmarton csordasmarton added this to the release 6.16.0 milestone Feb 24, 2021
@csordasmarton csordasmarton force-pushed the fix_create_session_file branch from 81b2814 to a91b7b8 Compare February 25, 2021 10:20
If we run multiple CodeChecker commands (login, store) which uses the same
home directory and the CodeChecker session file (`~/.codechecker.session.json`)
does not exist yet the following scenario is possible:
- The first command recognizes that this file doesn't exist yet so it will open
  this file for writing.
- Before the first command writes data to the file the second command will be run.
  It recognizes that the file exists, so it will read up the file. It expects that
  the file is a valid json file but it is empty. So the `token_dict` variable
  will be an empty dict, we try to get the `tokens` member of this empty
  dictionary (`self.__tokens`) which will be `None`, and when we will try to
  iterate over this directory (which is `None` in our case) the CodeChecker will
  raise an exception.

To solve this problem we will use `portalocker` after we opened the file to
lock it, so only one process will be able to read/write this file simultaneously.
Also we will handle the use case when this file is still empty.
@csordasmarton csordasmarton force-pushed the fix_create_session_file branch from a91b7b8 to 9a59c31 Compare February 25, 2021 10:22
@csordasmarton csordasmarton merged commit 17b25a6 into Ericsson:master Mar 1, 2021
@csordasmarton csordasmarton deleted the fix_create_session_file branch March 10, 2021 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix 🔨 CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants