Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hokoo committed May 5, 2024
1 parent f0a58e8 commit a4847ed
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/backend/class-wp-lock-backend-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,21 @@ public function drop_ghosts( $lock_id ) {

$locks = $wpdb->get_results( "SELECT * FROM {$this->get_table_name()} WHERE `lock_key` = '$lock_key'", ARRAY_A );
$ghosts = [];
foreach ( $locks as $lock ) {
if ( ! empty( $lock['expire'] ) && $lock['expire'] > microtime( true ) ) {
// This is an unexpired lock, keep it actual. No matter if it's a ghost or not.
continue;
}

// Remove unexpired locks from the list in order to keep them in DB.
$expired = array_filter(
$locks,
fn( $lock ) => empty( $lock['expire'] ) || $lock['expire'] <= microtime( true )
);

// Get active CIDs from the database to check if the given connections are still alive.
$active_cids = $wpdb->get_col( "SELECT id FROM information_schema.processlist WHERE id IN (" . implode( ',', array_column( $expired, 'cid' ) ) . ")" );

foreach ( $expired as $lock ) {
if (
( empty( $lock['pid'] ) && empty( $lock['cid'] ) ) ||
( ! empty( $lock['pid'] ) && ! file_exists( "/proc/{$lock['pid']}" ) ) ||
( ! empty( $lock['cid'] ) && empty(
$wpdb->get_var(
$wpdb->prepare( "SELECT id FROM information_schema.processlist WHERE id = %s", $lock['cid'] )
)
) )
( ! empty( $lock['cid'] ) && empty( array_filter( $active_cids, fn( $cid ) => $cid == $lock['cid'] ) ) )
) {
// This is a ghost lock, remove it.
$ghosts[] = $lock['id'];
Expand Down

0 comments on commit a4847ed

Please sign in to comment.