#3512 closed defect (fixed)

Client.init_tempdir clobbers global state in an annoying way

Reported by: exarkun Owned by: GitHub <noreply@…>
Priority: normal Milestone: undecided
Component: unknown Version: n/a
Keywords: Cc:
Launchpad Bug:

Description (last modified by exarkun)

    def init_tempdir(self):
        """
        Initialize/create a directory for temporary files.
        """
        tempdir_config = self.config.get_config("node", "tempdir", "tmp")
        if isinstance(tempdir_config, bytes):
            tempdir_config = tempdir_config.decode('utf-8')
        tempdir = self.config.get_config_path(tempdir_config)
        if not os.path.exists(tempdir):
            fileutil.make_dirs(tempdir)
        tempfile.tempdir = tempdir

This makes it impossible to have two Client instances in one process that are truly independent of each other. The last one to init will make all the rest share its temporary directory!

In the past this has caused a lot of problem for the test suite when the mutation doesn't get cleaned up. Some parts of the test suite nest more and more deeply into node temp dirs. Sometimes this blows up the OS path length limits. Other times it's just confusing. Most recently for ticket:2916 one test leaked a *unicode* value into tempfile.tempdir and broke some subsequent tests which suddenly got unicode temp directories instead of bytes temp directories.

The explanatory comment:

        # this should cause twisted.web.http (which uses
        # tempfile.TemporaryFile) to put large request bodies in the given
        # directory. Without this, the default temp dir is usually /tmp/,
        # which is frequently too small.

makes it seem as though this is *only* for Twisted Web intermediate files. We can fix these in a better way. Request.gotLength and Site.getContentFile both give us interfaces to control this behavior in a way that's localized to a single client.

Change History (3)

comment:1 Changed at 2020-11-18T18:40:34Z by exarkun

  • Description modified (diff)

comment:2 Changed at 2020-11-18T20:54:20Z by exarkun

  • Resolution set to duplicate
  • Status changed from new to closed

comment:3 Changed at 2020-11-25T23:18:41Z by GitHub <noreply@…>

  • Owner set to GitHub <noreply@…>
  • Resolution changed from duplicate to fixed

In 152c04e/trunk:

Merge pull request #902 from tahoe-lafs/3512.localized-tempdir

Per-node web temp directory

Fixes: ticket:3512

Note: See TracTickets for help on using tickets.