Skip to content

Segmentation Fault (core dumped)  #40

Closed

Description

@istvanskeri

I'm getting a segmentation fault error from my ratchet server while attempting to do

$process->stdin->write($json);

server is:

Ubuntu 14.4
PHP memory_limit = 128M
PHP 5.5.9

I'm using the following versions of ratchet and react child process

"cboden/ratchet": "^0.3.6",
"react/child-process": "^0.4.3"

code is working locally on os x and php 5.5.38

Activity

  1. WyriHaximus commented on Jun 28, 2017

    @WyriHaximus
    Member

    Do I assume correctly that $json is or should be a string?

  2. istvanskeri commented on Jun 28, 2017

    @istvanskeri
    Author

    correct. its a string and it is working for me locally. Not in production

  3. istvanskeri commented on Jun 28, 2017

    @istvanskeri
    Author

    $json var_dump is

    string(67) "{"command":"subscribe","comp_id":8481,"org_id":575,"user_id":64758}"

  4. clue commented on Jun 29, 2017

    @clue
    Member

    Hi @istvanskeri, thanks for reporting! I'm not sure I follow what you're trying to do and what your issue is, as it's a bit unclear what you're trying to achieve from the description you've posted.

    Where does the "Segmentation Fault (core dumped)" come from? Which process are you executing? When does this happen? Is this reproducible / does it happen all the time?

    May I ask you provide a simple gist of what you're trying to achieve? Thanks!

  5. istvanskeri commented on Jun 29, 2017

    @istvanskeri
    Author

    I have a ratchet server that waits for a socket message. When a message is received, a child process is created. The child process is a long running php script that sends back percentage completed back to the ratchet server that sends the percentage completed via socket back to the user. The ratchet server crashes with a Segmentation Fault (core dumped) message as soon as i try to do an stdin to the child process to pass variables to the long running php script.

    $process->stdin->write($json);

    https://gist.github.com/istvanskeri/15fd77afc641cd0013ef18cbbf7c7c27

  6. istvanskeri commented on Jul 7, 2017

    @istvanskeri
    Author

    We're thinking about upgrading our production server to php 7. Im hoping that will fix the seg fault issue. Will this library, and also ratchet work on php 7?

  7. WyriHaximus commented on Jul 7, 2017

    @WyriHaximus
    Member

    @istvanskeri To put it really simple: Yes it runs on PHP 7, been running it in production on 7 for more then a year now maybe two. You also get a free performance gain when upgrading to 7.

  8. nick4fake commented on Jul 17, 2017

    @nick4fake

    Hey, we have the same problem on PHP 5.5.10. Simply sending data to input of a process produces segfault.

  9. nick4fake commented on Jul 17, 2017

    @nick4fake

    @istvanskeri For us PHP7 is working correctly, but we can not update php ATM

  10. nick4fake commented on Jul 17, 2017

    @nick4fake

    Well, fix was trivial. Actually, it was even in the codebase:

    if (PHP_VERSION_ID < 50400) {
        stream_set_read_buffer($this->pipes[1], 1);
        stream_set_read_buffer($this->pipes[2], 1);
    }

    ->

    if (PHP_VERSION_ID <= 50510) {
        stream_set_read_buffer($this->pipes[1], 1);
        stream_set_read_buffer($this->pipes[2], 1);
    }
  11. clue commented on Jul 17, 2017

    @clue
    Member

    Thanks for reporting back on this!

    Can we pin point this to a certain program and/or PHP versions? What process are you executing and can this be reproduced easily? Ideally, a gist could help to diagnose this further 👍

  12. nick4fake commented on Jul 17, 2017

    @nick4fake

    @clue well, it looks like you have already fixed this problem previously, but limited fix version to PHP 5.3. I can try to create a test gist if you want, but we can rather simply apply this patch, as the only possible downside is IO performance when sending/fetching data while talking with cli script

  13. clue commented on Jul 17, 2017

    @clue
    Member

    This check is currently in place because the test suite would otherwise SEGFAULT, see 29aab03 for more details. If we can come up with a similar test case (or a gist which helps us create this test case), we may update the affected versions 👍

  14. istvanskeri commented on Jul 20, 2017

    @istvanskeri
    Author

    What steps can I take to get this working with PHP 5.5.9?

  15. clue commented on Jul 25, 2017

    @clue
    Member

    What steps can I take to get this working with PHP 5.5.9?

    What steps can we take to reproduce a SEGFAULT on PHP 5.5.9 (or any other version for that matter)?

    I'd like to check whether there's an issue here and if/how this can be fixed, but so far we've not been able to reproduce this.

  16. clue commented on Aug 8, 2017

    @clue
    Member

    Closing this due to a lack of feedback, as we can not reproduce this. Please come back with more details if this problem persists and we can reopen this 👍

  17. bryanburgers commented on Dec 20, 2017

    @bryanburgers

    I had this same issue on an old version of PHP 5.4.

    $ php --version
    PHP 5.4.15-1~precise+1 (cli) (built: May 13 2013 16:00:00) 
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    

    I could not reproduce the issue on php 5.4.45 (which is the PHP that comes when doing a docker pull php:5.4).

    In order to work around the issue, I also needed to do the stream_set_read_buffer fix.

    Since it seems unreasonable to determine which versions of PHP 5.4 this does and doesn't work for, and upstream a fix, all for a really old version of PHP, I'll leave what I did to work around it outside of the library here.

    $process = new React\ChildProcess\Process('echo one && sleep 1 && echo two');
    $process->start($loop);
    if (PHP_VERSION_ID < 50500)) {
        $reflection = new ReflectionProperty(get_class($process), 'pipes');
        $reflection->setAccessible(true);
        stream_set_read_buffer($reflection->getValue($process)[1], 1);
        stream_set_read_buffer($reflection->getValue($process)[2], 1);
    }
  18. clue commented on Dec 20, 2017

    @clue
    Member

    @bryanburgers Thank you for reporting back with another affected version! So far, we've been unable to reliable reproduce this issue and/or link this to a specific PHP version.

    I've just dug up an old PHP bug report that may be related here: https://bugs.php.net/bug.php?id=61019 (php/php-src@1ec83d4). This indicates this was fixed in 5.4.28+, 5.5.12+ and 5.6+ which seems to support the affected versions reported in this ticket so far.

    We've been able to reproduce this issue with PHP < 5.4 only so far via reactphp/stream#80. Unfortunately, Travis does not appear to allow us to test these legacy versions and I've been unable to test this elsewhere.

    Can anybody else confirm these version ranges?

  19. clue commented on Dec 20, 2017

    @clue
    Member

    Finally managed to reproduce this! 🎉

    <?php
    
    $p = popen('echo test', 'r');
    stream_set_blocking($p, false);
    stream_set_read_buffer($p, 0);
    
    var_dump(stream_get_contents($p));

    https://3v4l.org/g0A6U

    This confirms that this affects the above version range. I will look into filing a PR for our stream component to work around this issue :shipit:

  20. reopened this on Dec 20, 2017
  21. added this to the v0.5.1 milestone on Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions