Error during cache rebuild when assets are stored on NFS

Created on 19 November 2021, over 3 years ago
Updated 12 June 2025, 20 days ago

Problem/Motivation

We have two separate sites using Google Tag module with the assets directory hosted on NFS, and they both report an error when caches are cleared:

[warning] unlink(/var/www/html/web/sites/default/files/google_tag/CONTAINER/.nfs7015707d800127d2000016ab): Device or resource busy FileSystem.php:124

In FileSystem.php line 327:
                                                                               
  [Drupal\Core\File\Exception\FileException]                                   
  Failed to unlink file 'public://google_tag/CONTAINER/.nfs7015707d8001  
  27d2000016ab'.                                                               
                                                                               

Exception trace:
  at /var/www/html/web/core/lib/Drupal/Core/File/FileSystem.php:327
 Drupal\Core\File\FileSystem->delete() at /var/www/html/web/core/lib/Drupal/Core/File/FileSystem.php:372
 Drupal\Core\File\FileSystem->deleteRecursive() at /var/www/html/web/core/lib/Drupal/Core/File/FileSystem.php:365
 Drupal\Core\File\FileSystem->deleteRecursive() at /var/www/html/web/modules/contrib/google_tag/src/Entity/ContainerManager.php:255
 Drupal\google_tag\Entity\ContainerManager->deleteAssets() at /var/www/html/web/modules/contrib/google_tag/src/Entity/ContainerManager.php:243
 Drupal\google_tag\Entity\ContainerManager->deleteAllAssets() at /var/www/html/web/modules/contrib/google_tag/google_tag.module:62
 _google_tag_assets_delete() at /var/www/html/web/modules/contrib/google_tag/google_tag.module:42
 google_tag_rebuild() at n/a:n/a

This is apparently because of "silly rename" semantics on NFS; if a file is deleted while another process has it open on NFS, it is renamed to ".nfs" followed by a bunch of random numbers until the file is closed; this means that the directory itself can't be deleted. See http://nfs.sourceforge.net/#faq_d2 for more on this.

Steps to reproduce

Proposed resolution

Only delete the specific files and not the directory itself in ContainerManager::deleteAssets()?

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇷Brazil irafah

    Patch #5 won't work/is not needed anymore on version 2.0.8, as the changed file src/Entity/ContainerManager.php was removed

  • 🇦🇺Australia cafuego

    I assume the same logic is still used to delete directories, so the issue might still happen.

    However, I work around the problem now by moving generated asset dirs to a new temp dir on EFS during upgrades, so the Drupal code always tries to delete a new & empty dir, which always works.

Production build 0.71.5 2024