Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@gaeljw
Copy link
Member

@gaeljw gaeljw commented Jan 2, 2025

Pull Request Checklist

Helpful things

Fixes

Fixes #13013

Purpose

Do not try to delete the temporary folder during shutdown if it was never created in the 1st place. Because when trying to delete, it actually tries to create the folder if it was not already created. This is useless and can cause errors with read-only filesystems.

Background Context

I used a simple mutable var as I believe this is enough in this context: the var is private, in a singleton, only set during a lazy val initialization.
However, if you believe we should use an AtomicBoolean, just say it :)

Note that I didn't add test, not sure if this is worth it and I'm not sure how to approach writing such a test.

References

N/A


private val TempDirectoryPrefix = "playtemp"
private val TempDirectoryPrefix = "playtemp"
private var TempFolderCreated: Boolean = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @gaeljw! Thanks a lot to your contribution 👍
In common I agree with this approach, but personally, I would prefer to change type of private playTempFolder and use Option/Either for them instead of add a new boolean field. It'll be a more idiomatic way instead of manually sync a state of two Path and Boolean vars 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ihostage I agree it's not the best pattern but I wanted to keep the laziness of playTempFolder.

Are you suggesting to have a mutable Option[Path] and replace the lazy val creation of the folder by something like playTempFolder.getOrElse(create...) in the create method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I thought like this

private lazy val playTempFolder: Either[Throwable, Path] =
      try {
        ...
        Right(tmpFolder)
      } catch {
        case t: Throwable => Left(t)
      }

But now, I realize that this approach still creates and deletes a temporary folder unnecessarily, just potentially hide an error message in the log via the stop hook implementation. I don't like this. 😄
Need to think 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented the alternative you talked about in #13110

What do you guys think / prefer?
I don't really care.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight preference for my initial proposal that I find more explicit but I'm fine with yours as well.

Let's get one of the two merged :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative suggestion does not work anyway, because it can cause race conditions, see #13110 (comment)

Therefore lets just merge this PR finally.

…ry folder (fix playframework#13013)

With a read-only filesystem, an error was raised during shutdown when trying to delete the temporary
folder because delete would first create the folder if it was not yet created.

fix playframework#13013
@mkurz
Copy link
Member

mkurz commented Feb 16, 2025

@Mergifyio backport 3.0.x 2.9.x

@mergify
Copy link
Contributor

mergify bot commented Feb 16, 2025

This pull request has been removed from the queue for the following reason: pull request branch update failed.

The pull request can't be updated

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@mergify
Copy link
Contributor

mergify bot commented Feb 16, 2025

@mkurz
Copy link
Member

mkurz commented Feb 16, 2025

We can include this in our next patch release.

@mergify mergify bot merged commit 1be5242 into playframework:main Feb 16, 2025
31 checks passed
mkurz added a commit that referenced this pull request Feb 16, 2025
[2.9.x] Avoid error at shutdown if tmpdir is not writeable but was not used in the first place (backport #13039) by @gaeljw
mkurz added a commit that referenced this pull request Feb 16, 2025
[3.0.x] Avoid error at shutdown if tmpdir is not writeable but was not used in the first place (backport #13039) by @gaeljw
@gaeljw gaeljw deleted the gh13013 branch February 16, 2025 16:13
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

Successfully merging this pull request may close these issues.

Error at shutdown if tmpdir is not writeable even though it is not used

3 participants