[ARVADOS] updated: 2.3.1-4-ga0b4442a0

Git user git at public.arvados.org
Fri Dec 3 15:45:54 UTC 2021


Summary of changes:
 lib/controller/dblock/dblock.go | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

       via  a0b4442a02e4767ee63f03bc355538f16fffccb1 (commit)
      from  9e1fd027953d2d25f395144057dc9b95750a13f9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit a0b4442a02e4767ee63f03bc355538f16fffccb1
Author: Tom Clegg <tom at curii.com>
Date:   Tue Nov 30 10:57:08 2021 -0500

    18488: Close pg connection when waiting for lock.
    
    In practice, pg_advisory_lock() calls pile up and consume database
    connection slots, even when the corresponding processes have exited.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/lib/controller/dblock/dblock.go b/lib/controller/dblock/dblock.go
index b0d348870..1a36822d5 100644
--- a/lib/controller/dblock/dblock.go
+++ b/lib/controller/dblock/dblock.go
@@ -35,8 +35,8 @@ func (dbl *DBLocker) Lock(ctx context.Context, getdb func(context.Context) (*sql
 	for ; ; time.Sleep(retryDelay) {
 		dbl.mtx.Lock()
 		if dbl.conn != nil {
-			// Already locked by another caller in this
-			// process. Wait for them to release.
+			// Another goroutine is already locked/waiting
+			// on this lock. Wait for them to release.
 			dbl.mtx.Unlock()
 			continue
 		}
@@ -52,9 +52,15 @@ func (dbl *DBLocker) Lock(ctx context.Context, getdb func(context.Context) (*sql
 			dbl.mtx.Unlock()
 			continue
 		}
-		_, err = conn.ExecContext(ctx, `SELECT pg_advisory_lock($1)`, dbl.key)
+		var locked bool
+		err = conn.QueryRowContext(ctx, `SELECT pg_try_advisory_lock($1)`, dbl.key).Scan(&locked)
 		if err != nil {
-			logger.WithError(err).Infof("error getting pg_advisory_lock %d", dbl.key)
+			logger.WithError(err).Infof("error getting pg_try_advisory_lock %d", dbl.key)
+			conn.Close()
+			dbl.mtx.Unlock()
+			continue
+		}
+		if !locked {
 			conn.Close()
 			dbl.mtx.Unlock()
 			continue

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list