During cron runs the Twitter account are refreshed, but if an error occurs during this process an exception is thrown which is not caught. This will prevent other important cron tasks from running.

Some examples of errors I've seen occurring during cron:

  • Connection timed out
  • request timed out
  • Internal Server Error
  • Service Temporarily Unavailable
  • Service Unavailable
WD twitter: exception 'TwitterException' with message 'Connection timed out' in sites/all/modules/contrib/twitter/twitter.lib.php:284
Stack trace:
#0 sites/all/modules/contrib/twitter/twitter.lib.php(227): Twitter->request('http://api.twit...', Array, 'GET')
#1 sites/all/modules/contrib/twitter/twitter.lib.php(112): Twitter->call('statuses/user_t...', Array, 'GET', '0')
#2 sites/all/modules/contrib/twitter/twitter.lib.php(160): Twitter->get_statuses('statuses/user_t...', Array, '0')
#3 sites/all/modules/contrib/twitter/twitter.inc(125): Twitter->user_timeline('1410601', Array, '0')
#4 sites/all/modules/contrib/twitter/twitter.module(143): twitter_fetch_user_timeline('1410601')
#5 [internal function]: twitter_cron()
CommentFileSizeAuthor
#1 1567042-1-twitter-cron_exception.patch978 bytespfrenssen

Comments

pfrenssen’s picture

Status: Active » Needs review
StatusFileSize
new978 bytes
juampynr’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Needs review » Active
Issue tags: +needs backport to 6.x

Committed. Thanks.

http://drupalcode.org/project/twitter.git/commitdiff/f4a03bb6fb9132fbfc6...

See if you can make and test a patch for branch 6.x-3.x

pfrenssen’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev

Hmm somehow I encountered this problem again, I have received the following uncaught exception, even with the patch from #1 applied.

WD twitter: exception 'TwitterException' with message 'Service Unavailable' in sites/all/modules/contrib/twitter/twitter.lib.php:284
Stack trace:
#0 sites/all/modules/contrib/twitter/twitter.lib.php(227): Twitter->request('http://api.twit...', Array, 'GET')
#1 sites/all/modules/contrib/twitter/twitter.lib.php(112): Twitter->call('statuses/user_t...', Array, 'GET', '0')
#2 sites/all/modules/contrib/twitter/twitter.lib.php(160): Twitter->get_statuses('statuses/user_t...', Array, '0')
#3 sites/all/modules/contrib/twitter/twitter.inc(125): Twitter->user_timeline('172430303', Array, '0')
#4 sites/all/modules/contrib/twitter/twitter.module(144): twitter_fetch_user_timeline('172430303')
#5 [internal function]: twitter_cron()
pfrenssen’s picture

Ok it seems that I am mistaken about the entire issue. The exceptions were already caught successfully in Twitter::call():

  /**
   * Method for calling any twitter api resource
   */
  public function call($path, $params = array(), $method = 'GET', $use_auth = FALSE) {
    [...]
    try {
      if ($use_auth) {
        $response = $this->auth_request($url, $params, $method);
      }
      else {
        $response = $this->request($url, $params, $method);
      }
    }
    catch (TwitterException $e) {
      watchdog('twitter', '!message', array('!message' => $e->__toString()), WATCHDOG_ERROR);
      return FALSE;
    }
    [...]
  }

I am running cron from the CLI, and this causes a stack trace to be output to STDERR whenever exceptions occur, regardless of whether the exception is caught or not. I was mistaking these stack traces as fatal errors. Reading back the word "uncaught" is not even present in the error message, I have somehow overlooked this all the time.

Actually it transpires that the problem only existed in my head and my patch was not needed at all. It can best be reverted, it does not do any harm but is unneeded as the exceptions are already handled.

juampynr’s picture

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Added example exception backtrace to help people searching for this error