Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Building phar #714

Closed
pocallaghan opened this issue Oct 24, 2015 · 8 comments
Closed

Error Building phar #714

pocallaghan opened this issue Oct 24, 2015 · 8 comments

Comments

@pocallaghan
Copy link
Contributor

Pretty sure it's a localised issue, just hoping somebody else may have ran into the issue and have a solution. Every time I try and use ./build.sh I get the error:

Execution of target "dist_unix" failed for the following reason: ~/github/netz98/n98-magerun/build.xml:73:147: ~/github/netz98/n98-magerun/build.xml:73:147: Problem creating package: unable to create temporary file

I'm running a MBP with El Capitan and PHP 5.5.27. But I also tried a build on a ubuntu vagrant box with PHP 5.3 and got the same error.

@ktomk
Copy link
Collaborator

ktomk commented Oct 25, 2015

This can be related to file open limits. For a successful build this limit needs to be raised from the system standard configuration. I experienced this on my own already, it's a bit of a pity this is still not very well documented. So the references are a bit scattered:

Please let me know if you tried the build.sh from master and/or develop branch. Also as you intend to change the limits on your system, please before raising them report the limits you currently have. This could lead to a check we could put into build.sh to warn about this PHP / Phar related flaw.

How much this counts as an actual flaw in PHP is not totally clear to me, I can confirm you can prevent the error by raising the limits. Here some resources from the PHP bug tracker, perhaps it's worth to file another report as there still might be an underlying flaw with the Phar PHP extension:

In any case, please try with the limits. 500 000 should be sufficient, these worked for me.

@pocallaghan
Copy link
Contributor Author

I tried with both the master and develop branch and encountered the same error. Added the lines as suggested (in https://rtcamp.com/tutorials/linux/increase-open-files-limit/) and that allowed me to build. I'm not entirely sure what the old limit was, there was no lines in the files that weren't commented out.

#*               soft    core            0
#root            hard    core            100000
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#ftp             -       chroot          /ftp
#@student        -       maxlogins       4

@ktomk
Copy link
Collaborator

ktomk commented Oct 25, 2015

@pocallaghan Thanks for the detailed feedback and good to see you got it running.

ktomk added a commit that referenced this issue Oct 27, 2015
Comporessing a phar file needs a lot of open file descriptors/file handles, roughly as many as compressed files it contains.

As that limit is (for magerun normally) below the hard limit (of an assumed 4096), *build.sh* raises the soft-limit to the hard-limit prior running the phing build.

- The *build.sh* script raises the openfiles soft-limit to the maximum
  possible size (the hard-limit).

- The *build.sh* script did not exit with a non-zero exit status when it
  ran into an error on build. Fix by keeping the exit status and returning
  it.

- The patched phing task to create the phar file shows the number of files
  that are compressed.

- The patched phing task catches BadMethodCallException on
  Phar::compressFiles(), checks for the exception message and inserts a
  more-saying exception message in the middle.

This should alleviate the problem reported in #714. In case the error
happens again, more information should be available from the exception
message then.
@ktomk
Copy link
Collaborator

ktomk commented Oct 27, 2015

@pocallaghan: Good news, I reviewed this again and could find out more. First of all, on a fresh Ubuntu 14.04 64Bit system, I've got the following openfiles limits:

$ echo -n "soft: "; ulimit -Sn && echo -n "hard: "; ulimit -Hn
soft: 1024
hard: 4096

The build.sh script needs an openfiles limit of the number of files to compress plus a little offset for the script and PHP itself.

A limit of 1839 (that is 1834 files to be compressed in the phar file plus the offset of five for the script itself) did it for me then.

As this is between soft and hard limit, raising the soft-limit to the maximum should be a good "fix" on this issue.

Thanks again for taking the time to report this and the feedback you provided!

ktomk added a commit that referenced this issue Oct 27, 2015
Compressing a phar file needs a lot of open file descriptors/file handles, roughly as many as compressed files it contains.

As that limit is (for magerun normally) below the hard limit (of an assumed 4096), *build.sh* raises the soft-limit to the hard-limit prior running the phing build.

- The *build.sh* script raises the openfiles soft-limit to the maximum
  possible size (the hard-limit).

- The *build.sh* script did not exit with a non-zero exit status when it
  ran into an error on build. Fix by keeping the exit status and returning
  it.

- The patched phing task to create the phar file shows the number of files
  that are compressed.

- The patched phing task catches BadMethodCallException on
  Phar::compressFiles(), checks for the exception message and inserts a
  more-saying exception message in the middle.

This should alleviate the problem reported in #714. In case the error
happens again, more information should be available from the exception
message then.
@ktomk
Copy link
Collaborator

ktomk commented Oct 27, 2015

This should be fixed now, at least up to the hard-limit the system is configured for. I'll close this for now. I only write should because this can't be tested for all circumstances easily (for example, the travis server didn't have this problem on the openfiles limit so it got unnoticed as the system I wrote build.sh on was already "mis"configured (@pocallaghan 500 000 is quite high for this build.sh, so sorry for making this suggestion first. it works but is far off at least for magerun phar building. might be OK for a dev machine anyway)).

@ktomk ktomk closed this as completed Oct 27, 2015
@pocallaghan
Copy link
Contributor Author

I only changed it on a vagrant box I spun up specifically for the test so no bother. I had no idea such limits existed before this, every days a lesson. :)

@ktomk
Copy link
Collaborator

ktomk commented Oct 27, 2015

Yes, good teamwork! Also for me I now finally understood what's going on with the phar compression and why it triggers these limits. Everyday a lesson, that's a good saying (-:

ktomk added a commit that referenced this issue Oct 31, 2015
Compressing a phar file needs a lot of open file descriptors/file handles, roughly as many as compressed files it contains.

As that limit is (for magerun normally) below the hard limit (of an assumed 4096), *build.sh* raises the soft-limit to the hard-limit prior running the phing build.

- The *build.sh* script raises the openfiles soft-limit to the maximum
  possible size (the hard-limit).

- The *build.sh* script did not exit with a non-zero exit status when it
  ran into an error on build. Fix by keeping the exit status and returning
  it.

- The patched phing task to create the phar file shows the number of files
  that are compressed.

- The patched phing task catches BadMethodCallException on
  Phar::compressFiles(), checks for the exception message and inserts a
  more-saying exception message in the middle.

This should alleviate the problem reported in #714. In case the error
happens again, more information should be available from the exception
message then.
@ktomk
Copy link
Collaborator

ktomk commented Dec 26, 2016

(found some older notes which is better to placed here) Some internals: For the concrete exception message:

'BadMethodCallException' with message 'unable to create temporary file' in build/tasks/PatchedPharPackageTask.php:(line of Phar::compressFiles)

I suspect it is triggered by phar/phar.c#2846 ff which leads to entry->cfp which is a file pointer to the compressed tempfile. That handle is not closed within that loop but later on in a second loop. This is why Phar::compressFiles needs that many open files.

I can't say whether this construes a flaw or not. It looks to me that each file can be handeled with a different compression (no compression, gzip or bzip2) and that file-pointer holds the compressed data (as a pointer to a tempfile) until the phar file is written out later on phar/phar.c#3073 ff. This at least is expensive on the number of open file handles and doesn't scale well for a large number of files.

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

No branches or pull requests

2 participants