Skip to content

Temporary user data directory not always erased #46

@bch36

Description

@bch36

I've discovered that the temporary user data directory can sometimes be recreated after being deleted after the process is shut down cleanly. It's not consistent--sometimes it happens, sometimes it doesn't. I believe it's a timing issue. I believe what's happening is that after the main process is stopped and the directory is deleted, a child process (Chrome seems to spawn a lot!) will attempt to write something to the directory and thereby recreate it.

This seems to be confirmed by adding a "sleep" statement after stopping the process and before deleting the temporary user data dir. If we wait a few seconds before deleting the directory, it doesn't come back.

I'm happy to submit a pull request if desired, but it seems to be a pretty ugly fix--I just don't know a better way to wait until all the spawned child processes fully shut down.

ProcessInstance.php:

public function close(): void
{
	$this->process->stop();
	$this->process = null;

	sleep(5); // Adding this prevents temporaryUserDataDir from returning after it's removed

	if ($this->temporaryUserDataDir !== null) {
		(new Filesystem())->remove($this->temporaryUserDataDir);
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions