immobiliare / ApnsPHP

ApnsPHP: Apple Push Notification & Feedback Provider
BSD 3-Clause "New" or "Revised" License
1.43k stars 454 forks source link

Disconnect HTTP/2 after request failed #136

Open jonas0616 opened 7 years ago

jonas0616 commented 7 years ago

NFO: Process 1 has 1 messages, sending... INFO: Sending messages queue, run #1: 1 message(s) left in queue. ERROR: Unable to send message ID 1: {"reason":"BadDeviceToken"} (400). INFO: Disconnected. INFO: Trying to initialize HTTP/2 backend... INFO: Initialized HTTP/2 backend. INFO: Sending messages queue, run #2: 1 message(s) left in queue. ERROR: Unable to send message ID 1: {"reason":"BadDeviceToken"} (400). INFO: Disconnected. INFO: Trying to initialize HTTP/2 backend... INFO: Initialized HTTP/2 backend. INFO: Sending messages queue, run #3: 1 message(s) left in queue. ERROR: Unable to send message ID 1: {"reason":"BadDeviceToken"} (400). INFO: Disconnected. INFO: Trying to initialize HTTP/2 backend... INFO: Initialized HTTP/2 backend. INFO: Sending messages queue, run #4: 1 message(s) left in queue. WARNING: Message ID 1 [custom identifier: 497] has 3 errors, removing from queue...

According to APNS document: "Normal request failures do not result in termination of a connection". Is it overreacting that it disconnects when any request fails?

YohannsMonnier commented 6 years ago

Hello, we see exactly the same kind of problem. Did you find a solution about that ?

YohannsMonnier commented 6 years ago

The problem is on this function :

protected function _updateQueue($aErrorMessage = null)
    {
        $aStreamErrorMessage = $this->_readErrorMessage();
        if (!isset($aErrorMessage) && !isset($aStreamErrorMessage)) {
            return false;
        } else if (isset($aErrorMessage, $aStreamErrorMessage)) {
            if ($aStreamErrorMessage['identifier'] <= $aErrorMessage['identifier']) {
                $aErrorMessage = $aStreamErrorMessage;
                unset($aStreamErrorMessage);
            }
        } else if (!isset($aErrorMessage) && isset($aStreamErrorMessage)) {
            $aErrorMessage = $aStreamErrorMessage;
            unset($aStreamErrorMessage);
        }

        $this->_log('ERROR: Unable to send message ID ' .
            $aErrorMessage['identifier'] . ': ' .
            $aErrorMessage['statusMessage'] . ' (' . $aErrorMessage['statusCode'] . ').');

        $this->disconnect();

        foreach($this->_aMessageQueue as $k => &$aMessage) {
            if ($k < $aErrorMessage['identifier']) {
                unset($this->_aMessageQueue[$k]);
            } else if ($k == $aErrorMessage['identifier']) {
                $aMessage['ERRORS'][] = $aErrorMessage;
            } else {
                break;
            }
        }

        $this->connect();

        return true;
    }

I think that this is done this way because the code was shared between the two version of the library, the one working with socket and the one working with http2. With the HTTP2 version, we have doubt on the fact that doing disconnection and reconnection is necessary.