Skip to content

PushService not detecting fwrite failure #7

@GoogleCodeExporter

Description

@GoogleCodeExporter
What steps will reproduce the problem?
1. Send a successful push notification
2. Far end closes socket or socket becomes unusable
3. Try to send another Push notification and fwrite to the socket fails

What is the expected output? What do you see instead?

The fwrite error needs to be caught and a retry on another socket attempted..

What version of the product are you using? On what operating system?
Centos 5.3

Please provide any additional information below.

We were noticing the service hanging.
We solved this partly by adding the following to catch the socket fwrite
error in PushService.php. This now catches 75% of the hangs - there is
still another hang out there which we havent solved yet - we suspect
SendNotification is waiting for ever for a response to the fwrite:-

//Catch fwrite error in SendNotification
function sendNotification($deviceToken, $message)
{
//added catch fwrite error
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '',
$deviceToken)) . chr(0) . chr(strlen($message)) . $message;
$fwritten=fwrite($this->apnsConnection, $apnsMessage);
if ($fwritten==0 || $fwritten===FALSE || $fwritten < strlen($apnsMessage))
    {
    error_log(date('Y-m-d H:i')." - fwrite failed:\n".$message."\nTo device:
".$deviceToken."\n return = ".$fwritten."\n", 3, 'PushServiceError.log');
    return -1;
   }
return $fwritten;
}

//Spot the send failure in listenForClients()
function listenForClients()
    {
        $this->serviceConnection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        socket_bind($this->serviceConnection, $this->serviceHost,
$this->servicePort);
        socket_listen($this->serviceConnection, 10);

        echo 'LISTENING ',$this->servicePort,"\n";

        while($clientSocket = socket_accept($this->serviceConnection))
        {
            socket_write($clientSocket, "OK\n");

            $deviceToken = trim(socket_read($clientSocket, 1024, PHP_NORMAL_READ));
            $message = trim(socket_read($clientSocket, 1024, PHP_NORMAL_READ));

            if(!empty($deviceToken) && !empty($message))
            {
                //SB added catch fwrite error
                if ($this->sendNotification($deviceToken, $message) >= 0)
                {
                    socket_write($clientSocket, "SENT\n");
                }
                else
                {
                    socket_write($clientSocket, "ERROR\n");
                }
            }
            else
            {
                socket_write($clientSocket, "ERROR\n");
            }
            socket_close($clientSocket);
        }
    }


Original issue reported on code.google.com by snbenn...@gmail.com on 20 Oct 2009 at 8:49

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions