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

Execute targetcli commands concurrently raise EOFError #60

Open
zoumingzhe opened this issue Oct 19, 2021 · 1 comment
Open

Execute targetcli commands concurrently raise EOFError #60

zoumingzhe opened this issue Oct 19, 2021 · 1 comment

Comments

@zoumingzhe
Copy link

Hello, the following error occur intermittently when 10 targetcli commands are executed concurrently.

Traceback (most recent call last):
  File "/usr/bin/targetcli", line 329, in <module>
    main()
  File "/usr/bin/targetcli", line 254, in main
    shell = TargetCLI(getenv("TARGETCLI_HOME", '~/.targetcli'))
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 176, in __init__
    self.prefs.load()
  File "/usr/lib/python2.7/site-packages/configshell_fb/prefs.py", line 150, in load
    self._prefs = six.moves.cPickle.load(fsock)
EOFError
@zoumingzhe
Copy link
Author

zoumingzhe commented Oct 19, 2021

I think save in class Prefs used the wrong lock type 'fcntl.LOCK_UN'.
Please see pull #43 for details.
Then, call open via 'wb' will truncate the file without lock protection,
if load prefs.bin at the same time, maybe read empty prefs.bin and
cause EOFError with very low probability.

    def save(self, filename=None):
        '''
        Saves the preferences to disk. If filename is not specified,
        use the default one if it is set, else do nothing.
        @param filename: Optional alternate file to use.
        @type filename: str
        '''
        if filename is None:
            filename = self.filename

        if filename is not None:
            fsock = open(filename, 'wb')
            fcntl.lockf(fsock, fcntl.LOCK_UN)
            try:
                six.moves.cPickle.dump(self._prefs, fsock, 2)
            finally:
                fsock.close()

    def load(self, filename=None):
        '''
        Loads the preferences from file. Use either the supplied filename,
        or the default one if set. Else, do nothing.
        '''
        if filename is None:
            filename = self.filename

        if filename is not None and os.path.exists(filename):
            fsock = open(filename, 'rb')
            fcntl.lockf(fsock, fcntl.LOCK_SH)
            try:
                self._prefs = six.moves.cPickle.load(fsock)
            finally:
                fsock.close()

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

No branches or pull requests

1 participant