4

I had 2 similar questions before, however after more debugging I came to the conclusion the problem was (probably) not within my own code.

In my code I am trying to unzip a gzipped file, for this I wrote a small method;

<?php

namespace App\Helpers;

class Gzip
{

    public static function unzip($filePath)
    {
        $outFilePath = str_replace('.gz', '', $filePath);

        // Open our files (in binary mode)
        $file = gzopen($filePath, 'rb');
        $outFile = fopen($outFilePath, 'wb');

        // Keep repeating until the end of the input file
        while (!gzeof($file)) {
            // Read buffer-size bytes
            // Both fwrite and gzread and binary-safe
            fwrite($outFile, gzread($file, 4096));
        }

        // Files are done, close files
        fclose($outFile);
        gzclose($file);
    }
}

This should result in the unzipped file;

Gzip::unzip('path/to/file.csv.gz');

This is where it gets tricky, sometimes it will unzip the file and sometimes it will throw this exception; (keep in mind that this has nothing to do with the StreamHandler itself, this is a pure input/output error problem) exception fwrite

I can refresh the page as many times as I want but nothing will change, if I would try the gunzip command on the command line it will fail with sort off the same error; gunzip error

  • Which file I am unzipping does not matter, it randomly happens to a random file.

Now it also won't matter if I run the gunzip command multiple times, but like I said these exceptions / errors happen randomly so they also randomly "fix" them self.

The application is written in Laravel 8.0, PHP7.4 running on a Homestead environment (Ubuntu 18.04.5 LTS) my base laptop runs on Windows 10.

To me it's super weird that this exception / error happens randomly and also randomly out of nowhere "fixes" itself, so my question is: how does this happen, why does this happen and ultimately how can I fix it.

frogeyedman
  • 534
  • 1
  • 5
  • 23
  • fopen can fail, you need to check for this. It should be a file or folder permission issue. – Richard Tyler Miles Jan 04 '21 at 20:55
  • @TylerMiles has that any correlation with the ```gunzip``` command itself ? – frogeyedman Jan 04 '21 at 21:00
  • If you're using the same file it's possible you try to use it while it's still in use and get this error. – apokryfos Jan 04 '21 at 23:25
  • @apokryfos but why would the exception come up in the first place ? – frogeyedman Jan 05 '21 at 08:00
  • It’s hard to say, I would recommend opening an issue with the developer at the repo (hopefully on git). Run a try catch in a loop to just give it a retry when it fails... have a counter for max retries. Even if the process was halted by a signal your resources shouldn’t close. I do this in portions of my own code when dealing with socket resources or starting MySQL connections. – Richard Tyler Miles Jan 06 '21 at 00:15
  • @TylerMiles i do not think the StreamHandler is the problem, the StreamHandler fails because it will try to write the exception to the laravel logging which uses fwrite and that fails to. – frogeyedman Jan 06 '21 at 08:00
  • omg, I just got the same problem on the same cofig, but it was all right for ages... what did I change recently? I created and deleted a lot of talbes in the homestead mysql, so hopefully `vagrant-halt` / `vagrant up --provision` should do the trick. – Yevgeniy Afanasyev Apr 22 '21 at 06:47
  • I tested it and it looks like my Predis has died. – Yevgeniy Afanasyev Apr 22 '21 at 06:55

4 Answers4

3

errno=5 Input/output error is a failure to read/write the Linux file system.

A real server, you need to check the disk with fsck, etc...

Homestead running on Windows, I think we should look for the windows 10 homestead errno -5 issue.

winnfsd - https://github.com/winnfsd/vagrant-winnfsd/issues/96#issuecomment-336105685

Been Kyung-yoon
  • 1,644
  • 12
  • 13
  • Yes these were my exact thoughts, however I already tried to restart the NFS client after the error. This makes no difference at all, however I still think it has something to do with Vagrant + windows – frogeyedman Jan 12 '21 at 18:39
  • 1
    That's right, it's unfortunate that it doesn't help, but I wanted to help you find the cause of the error. Another solution is Laravel Sail. https://laravel.com/docs/8.x/sail – Been Kyung-yoon Jan 13 '21 at 00:55
  • Yes i may have to do that, however i'm more comfortable with vagrant (if its works.) – frogeyedman Jan 13 '21 at 07:39
2

If your Vagrant on Windows is using VirtualBox, HyperV can course this.

Try to disable HyperV for VirtualBox on the powershell, and reboot Windows

Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Hypervisor

regards

Maetti79
  • 46
  • 1
1

The problem relied in me using Homestead (a Vagrant box) with NFS turned on, Vagrant + NFS + Windows = problems. There are many possible solutions to the problem, most exceptions regarding a errno5 come down to NFS + Vagrant.

The solution for me was to stop using NFS, for now this will be the accepted answer as this fixes my problem. However if someone manages to find a actual solution to this error I will accept that.

frogeyedman
  • 534
  • 1
  • 5
  • 23
0

I solved it and I keep using NFS.

This situation happens to me usually when I'm dropping a database schema or creating a new one and fill it with a lot of data on my virtual box. I'm talking about volumes like around 50 Megabytes. I guess this is enough for virtual box to start re-scaling the virtual hard disc and it makes Ubuntu crazy and Kernel panicking.

So the solution is to reboot vagrant as many times as it takes for it to fix the issue.

That is what usually work for me:

  • make vagrant halt - it would go with errors
  • then vagrant up - it probably would not work
  • them vagrant halt - it probably would go with errors again
  • then vagrant up --provision - it would take time and probably also give errors
  • then vagrant halt - it should work this time
  • then vagrant up --provision - because "why not provisioning it again" and it is usually enough.

In 9 out of 10 cases it is enough. When it is not enough then I just create a new homestead.

Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191