Skip to content

pcntl_fork causing “errno=32 Broken pipe” #474

@penfold45

Description

@penfold45

Hi

I am having issues with PHP notices after upgrading from php 5.4.26 to 5.4.28. I original thought it was a php issue but it may be related to this Redis extension.

The full details can be found here http://stackoverflow.com/questions/23713480/after-php-upgrade-pcntl-fork-causing-errno-32-broken-pipe

But basically when I am forking, whenever a child closes, except for the first child, I get an error saying:

Notice: Unknown: send of 6 bytes failed with errno=32 Broken pipe in Unknown on line 0

It feels like the first child is closing the connection to Redis and then the following children try and close the same connection.

It appears that this has only just started being an issue since either PHP 5.4.27 or 5.4.28

Could this be a phpredis issue?

I have Redis Version => 2.2.5 installed

Activity

michael-grunder

michael-grunder commented on May 19, 2014

@michael-grunder
Member

Hey there,

While I don't know specifically why, I have a strong suspicion that the Zend library might get a little quirky around sockets within the context of a forking. That being said, I'll see if I can replicate your issue based on the stack overflow question you mentioned.

Cheers dude,
Mike

penfold45

penfold45 commented on May 19, 2014

@penfold45
Author

Brilliant thanks. For the time being I have just disabled php notice errors for the scripts that fork. Makes my log files a little quieter ;)

penfold45

penfold45 commented on Jun 5, 2014

@penfold45
Author

Hi. I was woundering if you have had chance to look into this yet?

penfold45

penfold45 commented on Sep 30, 2014

@penfold45
Author

Bump*

jessem

jessem commented on Oct 29, 2014

@jessem

+1 Also seeing this issue with workers that fork in PHPResque https://github.com/chrisboulton/php-resque

splitice

splitice commented on Nov 16, 2014

@splitice

+1 also seeing this in php resque workers.

Appears harmless... guessing its "QUIT\r\n"

added a commit that references this issue on Nov 18, 2014
jat001

jat001 commented on Jan 12, 2015

@jat001

I know how to fix this bug. Just close the connect to redis before pcntl_fork and re-connect to redis after pcntl_fork.

anton000

anton000 commented on Jan 21, 2015

@anton000

no updates?

roeyb

roeyb commented on Feb 3, 2015

@roeyb

+1

kaminono

kaminono commented on Feb 11, 2015

@kaminono

+1

rlweb

rlweb commented on Feb 20, 2015

@rlweb

+1

schlaus

schlaus commented on Mar 20, 2015

@schlaus

+1

lexaurin

lexaurin commented on Mar 26, 2015

@lexaurin

Same here. PHP 5.5.9, phpredis 2.2.7

Simple script to replicate this bug https://gist.github.com/lexaurin/8897f1be48b9e8747b7d/e8a5fcd750623b6fc250f9c529fc2e65cc55893a

Expected result:

bool(true)

Actual result:

bool(true)
PHP Notice:  Unknown: send of 6 bytes failed with errno=32 Broken pipe in Unknown on line 0

Notice: Unknown: send of 6 bytes failed with errno=32 Broken pipe in Unknown on line 0

PHP Notice:  Unknown: send of 6 bytes failed with errno=32 Broken pipe in Unknown on line 0

Notice: Unknown: send of 6 bytes failed with errno=32 Broken pipe in Unknown on line 0

Connections before script (lsof -i :6379):

COMMAND     PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
redis-ser 20319 root    4u  IPv4 10422993      0t0  TCP *:6379 (LISTEN)

Connections after first child forked:

COMMAND     PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
redis-ser 20319 root    4u  IPv4 10422993      0t0  TCP *:6379 (LISTEN)
redis-ser 20319 root    6u  IPv4 10446216      0t0  TCP config0.local:6379->config0.local:52050 (ESTABLISHED)
php       21993  lex    8u  IPv4 10446860      0t0  TCP config0.local:52050->config0.local:6379 (ESTABLISHED)
php       21994  lex    8u  IPv4 10446860      0t0  TCP config0.local:52050->config0.local:6379 (ESTABLISHED)

Connections after second child forked:

COMMAND     PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
redis-ser 20319 root    4u  IPv4 10422993      0t0  TCP *:6379 (LISTEN)
php       21993  lex    8u  IPv4 10446860      0t0  TCP config0.local:52050->config0.local:6379 (CLOSE_WAIT)
php       22020  lex    8u  IPv4 10446860      0t0  TCP config0.local:52050->config0.local:6379 (CLOSE_WAIT)

Connections after third child forked:

COMMAND     PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
redis-ser 20319 root    4u  IPv4 10422993      0t0  TCP *:6379 (LISTEN)

Note: Fact that child closes "both" connections at the end is right (since it shares file descriptor with parent).

lexaurin

lexaurin commented on Mar 26, 2015

@lexaurin

Modified my gist a bit to see which process produces notice https://gist.github.com/lexaurin/8897f1be48b9e8747b7d/d46ccd5c2ffabb1c3a09118db80654cb382c6c96
and it's interesting - third child at the end and following children and then parent at the end.

My log:

bool(true)
Parent pid: 22968
Child pid: 22969
Child pid: 22971
Child pid: 22972
Error in PID 22972: Unknown: send of 6 bytes failed with errno=32 Broken pipe
Child pid: 22973
Error in PID 22973: Unknown: send of 6 bytes failed with errno=32 Broken pipe
Child pid: 22974
Error in PID 22974: Unknown: send of 6 bytes failed with errno=32 Broken pipe
Error in PID 22968: Unknown: send of 6 bytes failed with errno=32 Broken pipe 

31 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rlweb@jessem@sanvibyfish@lexaurin@lixiphp

        Issue actions

          pcntl_fork causing “errno=32 Broken pipe” · Issue #474 · phpredis/phpredis