laravel/pulse

Getting a lot of database error

Closed this issue · 2 comments

Pulse Version

1.4.0

Laravel Version

11.44.1

PHP Version

8.4.3

Livewire Version

3.6.1

Database Driver & Version

pg17 (on the same connection that the application connection)

Description

During development, I have a container for the database and my application is running locally. To trigger this database error, there is no need to have the application running.

The database through the following error every seconds:

2025-03-07 13:10:34.239 UTC [42204] STATEMENT:  insert into "cache_locks" ("key", "owner", "expiration") values ($1, $2, $3)
2025-03-07 13:10:35.255 UTC [42204] ERROR:  duplicate key value violates unique constraint "cache_locks_pkey"
2025-03-07 13:10:35.255 UTC [42204] DETAIL:  Key (key)=(dev_maiamix_cache_laravel:pulse:check) already exists.
2025-03-07 13:10:35.255 UTC [42204] STATEMENT:  insert into "cache_locks" ("key", "owner", "expiration") values ($1, $2, $3)
2025-03-07 13:10:36.265 UTC [42204] ERROR:  duplicate key value violates unique constraint "cache_locks_pkey"
2025-03-07 13:10:36.265 UTC [42204] DETAIL:  Key (key)=(dev_maiamix_cache_laravel:pulse:check) already exists.
2025-03-07 13:10:36.265 UTC [42204] STATEMENT:  insert into "cache_locks" ("key", "owner", "expiration") values ($1, $2, $3)
2025-03-07 13:10:37.281 UTC [42204] ERROR:  duplicate key value violates unique constraint "cache_locks_pkey"
2025-03-07 13:10:37.281 UTC [42204] DETAIL:  Key (key)=(dev_maiamix_cache_laravel:pulse:check) already exists.
2025-03-07 13:10:37.281 UTC [42204] STATEMENT:  insert into "cache_locks" ("key", "owner", "expiration") values ($1, $2, $3)

(this issue also appears in production)

Steps To Reproduce

https://github.com/[Barbapapazes/pulse-reproduction](https://github.com/Barbapapazes/pulse-reproduction)

You've just to start the process pulse:check and then looking at postgres log.

Hi @Barbapapazes,

I think this is just the nature of how cache locks work when using the database store, rather than an actual error.

I can also replicate this without Pulse by doing the following:

$lock = Cache::store('database')->lock('foo', 5);

$lock->get(); // No error
$lock->get(); // DB will log an error because a lock with the same name already exists.

It's not ideal that this gets logged though.

Hey 👋,

Thanks for this answer! I understand it.

I'll close this issue as it's not a real bug, everything works fine even with this database error. I opened it to know if this was possible to remove it but it seems not.

I dive in the code and it is inevitable:

https://github.com/laravel/framework/blob/12.x/src/Illuminate/Cache/DatabaseLock.php#L67-L71

Thanks for the answer and have a nice day.