]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the unixIsSharingShmNode() code (check-in [6385a1962c69c69c]) to avoid branch-3.51
authordan <Dan Kennedy>
Mon, 15 Dec 2025 14:56:57 +0000 (14:56 +0000)
committerdan <Dan Kennedy>
Mon, 15 Dec 2025 14:56:57 +0000 (14:56 +0000)
possible deadlocks with threads in findResuableFd().

FossilOrigin-Name: f65aa46796068800905f6ff25efcb6338f864ce5bf8dcf6c7b9f5613b3973ab2

manifest
manifest.uuid
src/os_unix.c

index 99856fc85314ddcd151900db145e8973a1cc9859..f02a49b96f80682336c4bc4afa32c6f51b89dcbb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\sincorrect\sanswer\sthat\smight\sarise\sif\sa\sscalar\squery\sis\sboth\nDISTINCT\sand\scontains\san\sOFFSET\sclause.
-D 2025-12-09T13:29:08.680
+C Enhance\sthe\sunixIsSharingShmNode()\scode\s(check-in\s[6385a1962c69c69c])\sto\savoid\npossible\sdeadlocks\swith\sthreads\sin\sfindResuableFd().
+D 2025-12-15T14:56:57.780
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -720,7 +720,7 @@ F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63
 F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e06
 F src/os_kv.c fb7ba8d6204197357f1eb7e1c7450d09c10043bf7e99aba602f4aa46b8fb11a3
 F src/os_setup.h 8efc64eda6a6c2f221387eefc2e7e45fd5a3d5c8337a7a83519ba4fbd2957ae2
-F src/os_unix.c 7945ede1e85b2d1b910e1b4af9ba342e964b1e30e79f4176480a60736445cb36
+F src/os_unix.c dcf7988ddbdd68619b821c9a722f9377abb46f1d26c9279eb5a50402fd43d749
 F src/os_win.c a89b501fc195085c7d6c9eec7f5bd782625e94bb2a96b000f4d009703df1083f
 F src/os_win.h 4c247cdb6d407c75186c94a1e84d5a22cbae4adcec93fcae8d2bc1f956fd1f19
 F src/pager.c cd562b878ea1b44d021ba199abc9d3b54f6b3347500a9fed03f66d6000620945
@@ -2171,9 +2171,9 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 58a2a8417f2e0baade43e4da1c74893ab991cfbb34e5e5767d82f201c0b0b389
-Q +aef5397569d65d2971367b0278fe3a6f42544cf771572e7d046e2472f052364d
-R 6cbacd75cad3bb79ac6f69b5fc500a02
-U drh
-Z 4b715867d91a4e9be040246f23605a95
+P 35b306565a10c16737ee433728ca188852f01c12dfae0cc9212d21db932486fb
+Q +aa0a28776bbeafb71b2db20ac8c16377ba07b7d3d58e46cfd11f60c694759a90
+R b6d2a2df3700901831e3e349367a01e1
+U dan
+Z 7a7c58819650a66b89dae7071e983d1c
 # Remove this line to create a well-formed Fossil manifest.
index ffe7f58401d11d66f82e278061ccb2d35f7c4dd9..0a99f1fb14cccbd72bbe78718fc79ee92ba87276 100644 (file)
@@ -1 +1 @@
-35b306565a10c16737ee433728ca188852f01c12dfae0cc9212d21db932486fb
+f65aa46796068800905f6ff25efcb6338f864ce5bf8dcf6c7b9f5613b3973ab2
index 6b679c4dcd4c6dc0caded2c6da9e48aedfd2bcf8..d73d8992415d486770c43336b4a1367b1fd330d5 100644 (file)
@@ -2027,12 +2027,18 @@ static int unixLock(sqlite3_file *id, int eFileLock){
       pInode->nLock++;
       pInode->nShared = 1;
     }
-  }else if( (eFileLock==EXCLUSIVE_LOCK && pInode->nShared>1)
-         || unixIsSharingShmNode(pFile)
-  ){
+  }else if( eFileLock==EXCLUSIVE_LOCK && pInode->nShared>1 ){
     /* We are trying for an exclusive lock but another thread in this
     ** same process is still holding a shared lock. */
     rc = SQLITE_BUSY;
+  }else if( unixIsSharingShmNode(pFile) ){
+    /* We are in WAL mode and attempting to delete the SHM and WAL
+    ** files due to closing the connection or changing out of WAL mode,
+    ** but another process still holds locks on the SHM file, thus
+    ** indicating that database locks have been broken, perhaps due
+    ** to a rogue close(open(dbFile)) or similar.
+    */
+    rc = SQLITE_BUSY;
   }else{
     /* The request was for a RESERVED or EXCLUSIVE lock.  It is
     ** assumed that there is a SHARED or greater lock on the file
@@ -4671,26 +4677,21 @@ static int unixFcntlExternalReader(unixFile *pFile, int *piOut){
 ** still not a disaster.
 */
 static int unixIsSharingShmNode(unixFile *pFile){
-  int rc;
   unixShmNode *pShmNode;
+  struct flock lock;
   if( pFile->pShm==0 ) return 0;
   if( pFile->ctrlFlags & UNIXFILE_EXCL ) return 0;
   pShmNode = pFile->pShm->pShmNode;
-  rc = 1;
-  unixEnterMutex();
-  if( ALWAYS(pShmNode->nRef==1) ){
-    struct flock lock;
-    lock.l_whence = SEEK_SET;
-    lock.l_start = UNIX_SHM_DMS;
-    lock.l_len = 1;
-    lock.l_type = F_WRLCK;
-    osFcntl(pShmNode->hShm, F_GETLK, &lock);
-    if( lock.l_type==F_UNLCK ){
-      rc = 0;
-    }
-  }
-  unixLeaveMutex();
-  return rc;
+#if SQLITE_ATOMIC_INTRINSICS
+  assert( AtomicLoad(&pShmNode->nRef)==1 );
+#endif
+  memset(&lock, 0, sizeof(lock));
+  lock.l_whence = SEEK_SET;
+  lock.l_start = UNIX_SHM_DMS;
+  lock.l_len = 1;
+  lock.l_type = F_WRLCK;
+  osFcntl(pShmNode->hShm, F_GETLK, &lock);
+  return (lock.l_type!=F_UNLCK);
 }
 
 /*