Laravel-Excel icon indicating copy to clipboard operation
Laravel-Excel copied to clipboard

[Bug]: touch(): Unable to create file /app/storage/tmp/laravel-excel/laravel-excel-Lbgb6nfeSe1Hp9kL7ucC2qfZC3jFTNGX.xlsx because No such file or directory

Open oprypkhantc opened this issue 3 years ago • 1 comments
trafficstars

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • [X] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.40

What version of Laravel are you using?

9.11.0

What version of PHP are you using?

8.1.7

Describe your issue

This occurs in RemoteTemporaryFile when a local temp directory doesn't exist. For us this is the case a lot of the time as application containers are scaled back and forth, meaning every new container is missing that folder. A newly spawned container might be the one that's processing a ReadChunk job.

[object] (ErrorException(code: 0): touch(): Unable to create file /app/storage/tmp/laravel-excel/laravel-excel-Lbgb6nfeSe1Hp9kL7ucC2qfZC3jFTNGX.xlsx because No such file or directory at /app/vendor/maatwebsite/excel/src/Files/RemoteTemporaryFile.php:97)
[stacktrace]
#0 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(255): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /app/vendor/maatwebsite/excel/src/Files/RemoteTemporaryFile.php(97): touch()
#3 /app/vendor/maatwebsite/excel/src/Jobs/ReadChunk.php(150): Maatwebsite\\Excel\\Files\\RemoteTemporaryFile->sync()

TemporaryFileFactory has a fix for that, but unfortunately in this case it's never called, because this temporary file comes from deserialization of a job: https://github.com/SpartnerNL/Laravel-Excel/blob/3.1/src/Files/TemporaryFileFactory.php#L49

How can the issue be reproduced?

Not as simple to reproduce, but should be possible.

  1. Switch to a non-sync QUEUE_DRIVER - for example redis
  2. Call Excel::import(new UsersImport, 'users.xlsx');, but don't start the queue worker yet
  3. Go to storage/framework/cache and delete the laravel-excel directory.
  4. Run the queue worker.

What should be the expected behaviour?

A temporary files folder should be created prior to calling touch() on a temporary file which might not exist.

oprypkhantc avatar Sep 06 '22 17:09 oprypkhantc

Feel free to PR an improvement.

patrickbrouwers avatar Sep 13 '22 14:09 patrickbrouwers

This bug report has been automatically closed because it has not had recent activity. If this is still an active bug, please comment to reopen. Thank you for your contributions.

stale[bot] avatar Nov 14 '22 09:11 stale[bot]

I ran into a similar issue with vapor and fixed it by changing the config, see below

'local_path' => '/tmp',

'remote_disk' => 's3',

flowan avatar May 15 '23 18:05 flowan

For everyone who bumped into the same issue on vapor. this piece of code did the trick for me: image

egantz avatar Aug 10 '23 04:08 egantz