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

trap invalid opcode .... in phalcon.so #13143

Closed
ruudboon opened this issue Nov 2, 2017 · 13 comments
Closed

trap invalid opcode .... in phalcon.so #13143

ruudboon opened this issue Nov 2, 2017 · 13 comments
Assignees
Labels
bug A bug report status: low Low

Comments

@ruudboon
Copy link
Member

ruudboon commented Nov 2, 2017

I'm trying to run a phalcon docker build on coreOS using docker swarm.
My dockerfile is based from phalconphp/php:alpine-3-php7

Locally the image works fine (Mac).

I'm seeing the following errors:

[02-Nov-2017 18:39:12] WARNING: [pool www] child 86 exited on signal 4 (SIGILL - core dumped) after 315.152352 seconds from start
[522081.446459] traps: php-fpm[18560] trap invalid opcode ip:7fd1ddb83590 sp:7ffcd30b2b20 error:0 in phalcon.so[7fd1dd857000+686000]

/ # php --ri phalcon

phalcon


Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 3.2.2
Build Date => Aug 18 2017 13:56:35
Powered by Zephir => Version 0.9.9-868cb1f92b

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.disable_assign_setters => Off => Off
/ # php -v
PHP 7.1.5 (cli) (built: May 13 2017 10:49:18) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.5, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.5.3, Copyright (c) 2002-2017, by Derick Rethans
@ruudboon
Copy link
Member Author

ruudboon commented Nov 2, 2017

Upgraded to php 7.1.11 and phalcon 3.2.4, still same issue.

@ruudboon
Copy link
Member Author

ruudboon commented Nov 2, 2017

Pin pointed the issue to the router.

<?php
$router = new Phalcon\Mvc\Router();

/project/application/public # php index.php 
Illegal instruction (core dumped)

@ruudboon
Copy link
Member Author

ruudboon commented Nov 3, 2017

I think the problem is that I compile the docker image with my Mac as docker host and then push the image to my local repository. My staging env pull the image from the repository and tries to run it.
Looks like phalcon is linking to some host dependencies because when I rebuild phalcon inside the container on my staging environment it works.

I'm not a c++ expert so can't really tell what's happening. But I do think it should be possible to build the image on a different docker host and push it to the repository to run in on different docker host. Please correct me if I'm wrong.

@sergeyklay
Copy link
Contributor

Could you please provide the steps to reproduce?

@sergeyklay sergeyklay added Need information need script to reproduce Script is required to reproduce the issue labels Nov 19, 2017
@sergeyklay sergeyklay self-assigned this Nov 19, 2017
@h1kkan
Copy link

h1kkan commented Nov 22, 2017

Hi guys, i've faced same issue, and finded out root cause of it :)

it's caused by -mtune=native gcc build flag

I've builded docker image on AMD based host, tested it on the build host - and all was ok, and then we deploy it to AWS (Intel Xeon based EC2 instance) and get this errors:

[690962.001987] traps: php-fpm7.1[24545] trap invalid opcode ip:7f2a30d105d4 sp:7ffc2287e718 error:0 in phalcon.so[7f2a30c86000+476000]
[690963.423646] traps: php-fpm7.1[24562] trap invalid opcode ip:7fdc171105d4 sp:7fff597581d8 error:0 in phalcon.so[7fdc17086000+476000]
[690965.825258] traps: php-fpm7.1[24566] trap invalid opcode ip:7fb0017105d4 sp:7fffe7e133c8 error:0 in phalcon.so[7fb001686000+476000]
[690969.176541] traps: php-fpm7.1[24570] trap invalid opcode ip:7f9081b105d4 sp:7ffd2ad4c538 error:0 in phalcon.so[7f9081a86000+476000]

Then i tried to rebuild this docker image on Intel Xeon based host, deployed it to same EC2 instance - and issue was resolved :)

@sergeyklay
Copy link
Contributor

@ruudboon, @h1kkan Could you please remove -mtune=native from the build/install script and try reinstall Phalcon?

Refs: zephir-lang/php-zephir-parser#33

@sergeyklay sergeyklay added Bug - Low and removed Need information need script to reproduce Script is required to reproduce the issue labels Dec 14, 2017
@ruudboon
Copy link
Member Author

@sergeyklay Looks like this resolve the issue. Thnx

@ruudboon
Copy link
Member Author

I think there is something more happening. When creating a phalcon docker build on my Mac (Intel Core i7) I'm unable to run this container on my server with Xeon processor.
I tried removing -mtune=native but doesn't solve the issue. Building the same image on the Xeon environment works fine.

@ruudboon
Copy link
Member Author

ruudboon commented Feb 2, 2019

@ruudboon
Copy link
Member Author

ruudboon commented Feb 4, 2019

I think I've created a good example to show the issue.
A docker image I've builded on my Mac fails running on the my VPS (Linux 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux).

Backtrace

Core was generated by `php -r new Phalcon\Mvc\Router(); echo 'works';'.
Program terminated with signal SIGILL, Illegal instruction.
#0  0x00007f8f5088b4ae in zim_Phalcon_Mvc_Router_Route___construct () from /usr/local/lib/php/extensions/debug-non-zts-20180731/phalcon.so
(gdb) bt
#0  0x00007f8f5088b4ae in zim_Phalcon_Mvc_Router_Route___construct () from /usr/local/lib/php/extensions/debug-non-zts-20180731/phalcon.so
#1  0x00005640b386bc99 in zend_call_function ()
#2  0x00007f8f50546d95 in zephir_call_user_function () from /usr/local/lib/php/extensions/debug-non-zts-20180731/phalcon.so
#3  0x00007f8f50547321 in zephir_call_class_method_aparams () from /usr/local/lib/php/extensions/debug-non-zts-20180731/phalcon.so
#4  0x00007f8f5073c155 in zim_Phalcon_Mvc_Router___construct () from /usr/local/lib/php/extensions/debug-non-zts-20180731/phalcon.so
#5  0x00005640b38ec10c in ?? ()
#6  0x00005640b3958c0f in execute_ex ()
#7  0x00005640b395e20e in zend_execute ()
#8  0x00005640b386c8b6 in zend_eval_stringl ()
#9  0x00005640b386cabf in zend_eval_stringl_ex ()
#10 0x00005640b386cb45 in zend_eval_string_ex ()
#11 0x00005640b396115c in ?? ()
#12 0x00005640b39621c0 in ?? ()
#13 0x00007f8f54ba0ad6 in __libc_start_main () from /lib/ld-musl-x86_64.so.1
#14 0x0000000000000000 in ?? ()

This works on my Mac

 docker run ruudboon/phalcon-php-debug:latest -r "new Phalcon\Mvc\Router(); echo 'works';"

But fails on my vps (xeon).
To test it yourself you can start a terminal with this image

docker run -it --security-opt seccomp=unconfined --entrypoint=sh --rm ruudboon/phalcon-php-debug:latest

Then do

php  -r "new Phalcon\Mvc\Router();"

Depending on the system you will get Illegal instruction (core dumped) If a core dumped occurred you can create a backtrace.

apk add gdb
gdb php core
bt

@sergeyklay please let me know if you need more info

@ruudboon
Copy link
Member Author

ruudboon commented Feb 4, 2019

I've tested this on a few systems. On most systems it works. I now have 2 failing places. The VPS where it started with and an old Mac Pro from 2009 with an XEON cpu.

@ruudboon
Copy link
Member Author

ruudboon commented Feb 4, 2019

After reading this I solved the issue.
The -march takes precedence in relation with -mtune. Wil create a pull for that.

@ruudboon ruudboon mentioned this issue Feb 4, 2019
3 tasks
ruudboon added a commit to phalcon-orphanage/docs that referenced this issue Feb 6, 2019
Documentation for build change. See phalcon/cphalcon#13143
@niden
Copy link
Member

niden commented Feb 6, 2019

This has been addressed

@niden niden closed this as completed Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: low Low
Projects
None yet
Development

No branches or pull requests

4 participants