ApnsPHP icon indicating copy to clipboard operation
ApnsPHP copied to clipboard

Disconnect HTTP/2 after request failed

Open jonas0616 opened this issue 8 years ago • 2 comments

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?

jonas0616 avatar Sep 20 '16 07:09 jonas0616

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

YohannsMonnier avatar Aug 21 '17 12:08 YohannsMonnier

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.

YohannsMonnier avatar Aug 21 '17 13:08 YohannsMonnier