Advisory Lock returns `null`
See original GitHub issueWhen attempting to obtain an advisory lock: https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock
I’m receiving a null
response instead of the 0
or 1
as specified by the MySQL documentation and as seen when I issue the query through the MySQL client.

import test from 'ava'
import mysql from 'mysql2'
const pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'root',
port: 3306,
database: 'test',
password: '',
})
const foo = () => new Promise((resolve) => {
resolve(1)
})
const multiQuery = () => new Promise((resolve, reject) => {
const sql = `
SELECT GET_LOCK('test2', -1) AS test3;
`
pool.query(sql, (err, res) => (err == null ? resolve(res) : reject(err)))
})
test(async (t) => {
const response = await multiQuery()
console.log(response)
t.is(await foo(), 1)
})
Response:
Is this expected?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Advisory Lock from the nodejs mysql and mysql2 driver ...
Both implementations return NULL if an error occurred, however, the MariaDB does not support the negative timeout.
Read more >How do PostgreSQL advisory locks work - Vlad Mihalcea
Session-level advisory locks need to be released explicitly. Even if advisory locks are reentrant, if you acquired the same lock twice, you need ......
Read more >PostgreSQL Advisory Locks - Netguru
Advisory locks. Those locks are database based, stored in the pg_locks table. This simple SQL query will return currently obtained locks:
Read more >9.24. System Administration Functions - PostgreSQL
pg_advisory_unlock will release a previously-acquired exclusive session level advisory lock. It returns true if the lock is successfully released. If the lock ...
Read more >MySQL 5.7 Reference Manual :: 12.15 Locking Functions
Returns 1 if the lock was obtained successfully, 0 if the attempt timed out (for example, because another client has previously locked the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sidorares thank you for your help
It is an issue with MariaDB vs MySql. MariaDB doesn’t seem to support the negative timeout.
From the MySql Docs
The MariaDB Docs omit that line:
I apologize, I did not notice the difference.
Results when using a positive integer for the timeout: