From dc0ae2785dfe47db9cc1ead44fe64b89137d18f6 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 3 Mar 2014 00:01:13 +0100 Subject: [PATCH] SubMirror now works again against old PuSH There was a problem with (specifically at least) PuSHpress for Wordpress. A previous attempt to perform a DB transaction backfired because the remote side could connect to the callback before our commit had gone through. I take full responsibility for introducing the bug in the first place :) --- plugins/OStatus/actions/pushcallback.php | 2 +- plugins/OStatus/classes/FeedSub.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/OStatus/actions/pushcallback.php b/plugins/OStatus/actions/pushcallback.php index f68ef7693e..1dab72b2e0 100644 --- a/plugins/OStatus/actions/pushcallback.php +++ b/plugins/OStatus/actions/pushcallback.php @@ -52,7 +52,7 @@ class PushCallbackAction extends Action } $feedsub = FeedSub::getKV('id', $feedid); - if (!$feedsub) { + if (!$feedsub instanceof FeedSub) { // TRANS: Server exception. %s is a feed ID. throw new ServerException(sprintf(_m('Unknown PuSH feed id %s'),$feedid), 400); } diff --git a/plugins/OStatus/classes/FeedSub.php b/plugins/OStatus/classes/FeedSub.php index 2e62c512d1..dc0f4ea1e2 100644 --- a/plugins/OStatus/classes/FeedSub.php +++ b/plugins/OStatus/classes/FeedSub.php @@ -261,11 +261,16 @@ class FeedSub extends Managed_DataObject } /** + * Setting to subscribe means it is _waiting_ to become active. This + * cannot be done in a transaction because there is a chance that the + * remote script we're calling (as in the case of PuSHpress) performs + * the lookup _while_ we're POSTing data, which means the transaction + * never completes (PushcallbackAction gets an 'inactive' state). + * * @return boolean true on successful sub/unsub, false on failure */ protected function doSubscribe($mode) { - $this->query('BEGIN'); $orig = clone($this); if ($mode == 'subscribe') { $this->secret = common_random_hexstr(32); @@ -302,7 +307,6 @@ class FeedSub extends Managed_DataObject $response = $client->post($hub, $headers, $post); $status = $response->getStatus(); if ($status == 202) { - $this->query('COMMIT'); common_log(LOG_INFO, __METHOD__ . ': sub req ok, awaiting verification callback'); return true; } else if ($status >= 200 && $status < 300) { @@ -310,9 +314,7 @@ class FeedSub extends Managed_DataObject } else { common_log(LOG_ERR, __METHOD__ . ": sub req failed with HTTP $status: " . $response->getBody()); } - $this->query('ROLLBACK'); } catch (Exception $e) { - $this->query('ROLLBACK'); // wtf! common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub $this->huburi subscribing to $this->uri");