updated plugin Jetpack Protect version 1.1.2

This commit is contained in:
2022-12-19 23:08:19 +00:00
committed by Gitium
parent dcc5b4d910
commit 7b2202370c
91 changed files with 1019 additions and 656 deletions

View File

@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.44.0] - 2022-11-30
### Added
- Added full response logging for failed Sync data requests. [#27644]
### Fixed
- Make sure Dedicated Sync can revert back to Default Sync if it stops sending events for one reason or another. [#27632]
## [1.43.2] - 2022-11-28
### Changed
- Sync: Limit next_sync_time lock to be at most 1 hour in the future [#27606]
## [1.43.1] - 2022-11-22
### Changed
- Updated package dependencies. [#27043]
## [1.43.0] - 2022-11-17
### Added
- Added new sync option for launch-status [#27434]
@ -761,6 +776,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Packages: Move sync to a classmapped package
[1.44.0]: https://github.com/Automattic/jetpack-sync/compare/v1.43.2...v1.44.0
[1.43.2]: https://github.com/Automattic/jetpack-sync/compare/v1.43.1...v1.43.2
[1.43.1]: https://github.com/Automattic/jetpack-sync/compare/v1.43.0...v1.43.1
[1.43.0]: https://github.com/Automattic/jetpack-sync/compare/v1.42.0...v1.43.0
[1.42.0]: https://github.com/Automattic/jetpack-sync/compare/v1.41.0...v1.42.0
[1.41.0]: https://github.com/Automattic/jetpack-sync/compare/v1.40.3...v1.41.0

View File

@ -4,15 +4,15 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.46",
"automattic/jetpack-constants": "^1.6",
"automattic/jetpack-identity-crisis": "^0.8",
"automattic/jetpack-password-checker": "^0.2",
"automattic/jetpack-roles": "^1.4",
"automattic/jetpack-status": "^1.15"
"automattic/jetpack-connection": "^1.47.0",
"automattic/jetpack-constants": "^1.6.19",
"automattic/jetpack-identity-crisis": "^0.8.32",
"automattic/jetpack-password-checker": "^0.2.8",
"automattic/jetpack-roles": "^1.4.18",
"automattic/jetpack-status": "^1.15.1"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.2",
"automattic/jetpack-changelogger": "^3.2.1",
"yoast/phpunit-polyfills": "1.0.3",
"automattic/wordbless": "@dev"
},
@ -47,7 +47,7 @@
"link-template": "https://github.com/Automattic/jetpack-sync/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.43.x-dev"
"dev-trunk": "1.44.x-dev"
}
},
"config": {

View File

@ -355,13 +355,14 @@ class Actions {
$full_queue = self::$sender->get_full_sync_queue();
$debug['debug_details']['sync_locks'] = array(
'retry_time_sync' => get_option( self::RETRY_AFTER_PREFIX . 'sync' ),
'retry_time_full_sync' => get_option( self::RETRY_AFTER_PREFIX . 'full_sync' ),
'next_sync_time_sync' => self::$sender->get_next_sync_time( 'sync' ),
'next_sync_time_full_sync' => self::$sender->get_next_sync_time( 'full_sync' ),
'queue_locked_sync' => $queue->is_locked(),
'queue_locked_full_sync' => $full_queue->is_locked(),
'dedicated_sync_request_lock' => \Jetpack_Options::get_raw_option( Dedicated_Sender::DEDICATED_SYNC_REQUEST_LOCK_OPTION_NAME, null ),
'retry_time_sync' => get_option( self::RETRY_AFTER_PREFIX . 'sync' ),
'retry_time_full_sync' => get_option( self::RETRY_AFTER_PREFIX . 'full_sync' ),
'next_sync_time_sync' => self::$sender->get_next_sync_time( 'sync' ),
'next_sync_time_full_sync' => self::$sender->get_next_sync_time( 'full_sync' ),
'queue_locked_sync' => $queue->is_locked(),
'queue_locked_full_sync' => $full_queue->is_locked(),
'dedicated_sync_request_lock' => \Jetpack_Options::get_raw_option( Dedicated_Sender::DEDICATED_SYNC_REQUEST_LOCK_OPTION_NAME, null ),
'dedicated_sync_temporary_disable_flag' => get_transient( Dedicated_Sender::DEDICATED_SYNC_TEMPORARY_DISABLE_FLAG ),
);
// Sync Logs.
@ -494,12 +495,7 @@ class Actions {
// Enable/Disable Dedicated Sync flow via response headers.
$dedicated_sync_header = $rpc->get_response_header( 'Jetpack-Dedicated-Sync' );
if ( false !== $dedicated_sync_header ) {
$dedicated_sync_enabled = 'on' === $dedicated_sync_header ? 1 : 0;
Settings::update_settings(
array(
'dedicated_sync_enabled' => $dedicated_sync_enabled,
)
);
Dedicated_Sender::maybe_change_dedicated_sync_status_from_wpcom_header( $dedicated_sync_header );
}
if ( ! $result ) {
@ -517,7 +513,9 @@ class Actions {
$error_log = array_slice( $error_log, -4, null, true );
}
// Add new error indexed to time.
$error_log[ (string) microtime( true ) ] = $rpc->get_jetpack_error();
$error = $rpc->get_jetpack_error();
$error->add_data( $rpc->get_last_response() );
$error_log[ (string) microtime( true ) ] = $error;
// Update the error log.
update_option( self::ERROR_LOG_PREFIX . $queue_id, $error_log );
@ -1049,21 +1047,29 @@ class Actions {
* @access public
* @static
* @since 1.43.0
*
* @param bool $unlock_queues Whether to unlock Sync queues. Defaults to true.
*/
public static function reset_sync_locks() {
public static function reset_sync_locks( $unlock_queues = true ) {
// Next sync locks.
delete_option( Sender::NEXT_SYNC_TIME_OPTION_NAME . '_sync' );
delete_option( Sender::NEXT_SYNC_TIME_OPTION_NAME . '_full_sync' );
delete_option( Sender::NEXT_SYNC_TIME_OPTION_NAME . '_full-sync-enqueue' );
// Retry after locks.
delete_option( self::RETRY_AFTER_PREFIX . '_sync' );
delete_option( self::RETRY_AFTER_PREFIX . '_full_sync' );
// Dedicated sync lock.
delete_option( self::RETRY_AFTER_PREFIX . 'sync' );
delete_option( self::RETRY_AFTER_PREFIX . 'full_sync' );
// Dedicated sync locks.
\Jetpack_Options::delete_raw_option( Dedicated_Sender::DEDICATED_SYNC_REQUEST_LOCK_OPTION_NAME );
delete_transient( Dedicated_Sender::DEDICATED_SYNC_TEMPORARY_DISABLE_FLAG );
// Queue locks.
$sync_queue = new Queue( 'sync' );
$sync_queue->unlock();
$full_sync_queue = new Queue( 'full_sync' );
$full_sync_queue->unlock();
// Note that we are just unlocking the queues here, not reseting them.
if ( $unlock_queues ) {
$sync_queue = new Queue( 'sync' );
$sync_queue->unlock();
$full_sync_queue = new Queue( 'full_sync' );
$full_sync_queue->unlock();
}
}
}

View File

@ -50,6 +50,11 @@ class Dedicated_Sender {
*/
const DEDICATED_SYNC_REQUEST_LOCK_QUERY_PARAM_NAME = 'request_lock_id';
/**
* The name of the transient to use to temporarily disable enabling of Dedicated sync.
*/
const DEDICATED_SYNC_TEMPORARY_DISABLE_FLAG = 'jetpack_sync_dedicated_sync_temp_disable';
/**
* Filter a URL to check if Dedicated Sync is enabled.
* We need to remove slashes and then run it through `urldecode` as sometimes the
@ -111,7 +116,7 @@ class Dedicated_Sender {
*
* @access public
*
* @param Automattic\Jetpack\Sync\Queue $queue Queue object.
* @param \Automattic\Jetpack\Sync\Queue $queue Queue object.
*
* @return boolean|WP_Error True if spawned, WP_Error otherwise.
*/
@ -139,6 +144,41 @@ class Dedicated_Sender {
if ( $sync_next_time > microtime( true ) ) {
return new WP_Error( 'sync_throttled_' . $queue->id );
}
/**
* How much time to wait before we start suspecting Dedicated Sync is in trouble.
*/
$queue_send_time_threshold = 30 * MINUTE_IN_SECONDS;
$queue_lag = $queue->lag();
// Only check if we're failing to send events if the queue lag is longer than the threshold.
if ( $queue_lag > $queue_send_time_threshold ) {
/**
* Check if Dedicated Sync is healthy and revert to Default Sync if such case is detected.
*/
$last_successful_queue_send_time = get_option( Actions::LAST_SUCCESS_PREFIX . $queue->id, null );
if ( $last_successful_queue_send_time === null ) {
/**
* No successful sync sending completed. This might be either a "new" sync site or a site that's totally stuck.
*/
self::on_dedicated_sync_lag_not_sending_threshold_reached();
return new WP_Error( 'dedicated_sync_not_sending', 'Dedicated Sync is not successfully sending events' );
} else {
/**
* We have recorded a successful sending of events. Let's see if that is not too long ago in the past.
*/
$time_since_last_succesful_send = time() - $last_successful_queue_send_time;
if ( $time_since_last_succesful_send > $queue_send_time_threshold ) {
// We haven't successfully sent stuff in more than 30 minutes. Revert to Default Sync
self::on_dedicated_sync_lag_not_sending_threshold_reached();
return new WP_Error( 'dedicated_sync_not_sending', 'Dedicated Sync is not successfully sending events' );
}
}
}
/**
* Try to acquire a request lock, so we don't spawn multiple requests at the same time.
@ -312,4 +352,60 @@ class Dedicated_Sender {
return self::DEDICATED_SYNC_VALIDATION_STRING === $dedicated_sync_response_body;
}
/**
* Disable dedicated sync and set a transient to prevent re-enabling it for some time.
*
* @return void
*/
public static function on_dedicated_sync_lag_not_sending_threshold_reached() {
set_transient( self::DEDICATED_SYNC_TEMPORARY_DISABLE_FLAG, true, 6 * HOUR_IN_SECONDS );
Settings::update_settings(
array(
'dedicated_sync_enabled' => 0,
)
);
// Inform that we had to temporarily disable Dedicated Sync
$data = array(
'timestamp' => microtime( true ),
// Send the flow type that was attempted.
'sync_flow_type' => 'dedicated',
);
$sender = Sender::get_instance();
$sender->send_action( 'jetpack_sync_flow_error_temp_disable', $data );
}
/**
* Disable or enable Dedicated Sync sender based on the header value returned from WordPress.com
*
* @param string $dedicated_sync_header The Dedicated Sync header value - `on` or `off`.
*
* @return bool Whether Dedicated Sync is going to be enabled or not.
*/
public static function maybe_change_dedicated_sync_status_from_wpcom_header( $dedicated_sync_header ) {
$dedicated_sync_enabled = 'on' === $dedicated_sync_header ? 1 : 0;
// Prevent enabling of Dedicated sync via header flag if we're in an autoheal timeout.
if ( $dedicated_sync_enabled ) {
$check_transient = get_transient( self::DEDICATED_SYNC_TEMPORARY_DISABLE_FLAG );
if ( $check_transient ) {
// Something happened and Dedicated Sync should not be automatically re-enabled.
return false;
}
}
Settings::update_settings(
array(
'dedicated_sync_enabled' => $dedicated_sync_enabled,
)
);
return Settings::is_dedicated_sync_enabled();
}
}

View File

@ -12,7 +12,7 @@ namespace Automattic\Jetpack\Sync;
*/
class Package_Version {
const PACKAGE_VERSION = '1.43.0';
const PACKAGE_VERSION = '1.44.0';
const PACKAGE_SLUG = 'sync';

View File

@ -227,13 +227,29 @@ class Sender {
/**
* Retrieve the next sync time.
*
* Update @since 1.43.2
* Sometimes when we process Sync requests in Jetpack, the server clock can be a
* bit in the future and this can lock Sync to not send stuff for a while.
* We are introducing an extra check, to make sure to limit the next_sync_time
* to be at most one hour in the future from the current time.
*
* @access public
*
* @param string $queue_name Name of the queue.
* @return float Timestamp of the next sync.
*/
public function get_next_sync_time( $queue_name ) {
return (float) get_option( self::NEXT_SYNC_TIME_OPTION_NAME . '_' . $queue_name, 0 );
$option_name = self::NEXT_SYNC_TIME_OPTION_NAME . '_' . $queue_name;
$next_sync_time = (float) get_option( $option_name, 0 );
$is_more_than_one_hour = ( $next_sync_time - microtime( true ) ) >= HOUR_IN_SECONDS;
if ( $is_more_than_one_hour ) {
delete_option( $option_name );
$next_sync_time = 0;
}
return $next_sync_time;
}
/**
@ -944,10 +960,8 @@ class Sender {
foreach ( Modules::get_modules() as $module ) {
$module->reset_data();
}
foreach ( array( 'sync', 'full_sync', 'full-sync-enqueue' ) as $queue_name ) {
delete_option( self::NEXT_SYNC_TIME_OPTION_NAME . '_' . $queue_name );
}
// Reset Sync locks without unlocking queues since we already reset those.
Actions::reset_sync_locks( false );
Settings::reset_data();
}