#5897 chdir race condition
Closed: wontfix 6 years ago Opened 7 years ago by cheimes.

I noticed that FreeIPA uses chdir in several place. chdir() must never be used in a multi-threaded or concurrent application because it affects a global state. It can lead to race condition that a very hard to track. FreeIPA should use the cwd argument of subprocess / ipautil.run instead. It is safe because chdir is executed in the child process after fork().

$ find -name '*.py' -and -not -name setup.py | xargs grep chdir
./ipaserver/install/ipa_backup.py:                os.chdir(cwd)
./ipaserver/install/ipa_backup.py:        os.chdir(self.dir)
./ipaserver/install/ipa_restore.py:                os.chdir(cwd)
./ipaserver/install/ipa_restore.py:        os.chdir(self.dir)
./ipaserver/install/ipa_restore.py:        os.chdir(cwd)
./ipaserver/install/ipa_restore.py:        os.chdir('/')
./ipaserver/install/ipa_restore.py:        os.chdir(cwd)
./ipaserver/install/ipa_restore.py:        os.chdir(self.dir)
./ipaserver/install/certs.py:            os.chdir(self.cwd)
./ipaserver/install/certs.py:        os.chdir(self.reqdir)
./ipatests/test_ipapython/test_ipap11helper.py:    os.chdir(token_path)

Pretty sure these are all single-threaded applications. Backup and restore certainly are and anything in install should be. Don't know about the test but I don't think we run them in parallel currently.

Metadata Update from @cheimes:
- Issue assigned to someone
- Issue set to the milestone: Ticket Backlog

7 years ago

chdir is only used in single-threaded scripts and hasn't caused any trouble yet.

Metadata Update from @cheimes:
- Issue close_status updated to: None

6 years ago

Metadata Update from @cheimes:
- Issue close_status updated to: wontfix
- Issue status updated to: Closed (was: Open)

6 years ago

Login to comment on this ticket.

Metadata