diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike
index 8941eecc63787288089668cdc89bb1bc4d6086bb..c5cda7f21a1c971a1ab7e02f4c1eeae1a2c0a6a1 100644
--- a/lib/modules/Sql.pmod/pgsql.pike
+++ b/lib/modules/Sql.pmod/pgsql.pike
@@ -568,12 +568,10 @@ private void resync_cb() {
           resynced = Thread.Condition();
           resyncmux = Thread.Mutex();
         }
+        Thread.MutexKey lock = resyncmux->lock();
         proxy.readyforquery_cb = resync_cb;
         proxy.sendsync();
-        if (proxy.readyforquery_cb) {
-          Thread.MutexKey lock = resyncmux->lock();
-          resynced.wait(lock);	      // Wait for the db to finish
-        }
+        resynced.wait(lock);	      // Wait for the db to finish
       }
       return;
     };