# Shopify\_app gem: Database lock pile-ups when Shopify's token endpoint is slow

**URL:** <https://community.shopify.dev/t/shopify-app-gem-database-lock-pile-ups-when-shopifys-token-endpoint-is-slow/39201>\
**Category:** Authentication & Access\
**Created:** [October 29, 2026, 5:18pm UTC](https://community.shopify.dev/t/shopify-app-gem-database-lock-pile-ups-when-shopifys-token-endpoint-is-slow/39201 "2026-10-29T17:18:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andersonmacedo](https://sea1.discourse-cdn.com/shopifycommunity/user_avatar/community.shopify.dev/andersonmacedo/32/21902_2.png) [@andersonmacedo](https://community.shopify.dev/u/andersonmacedo)\
**Post date:** [October 29, 2026, 5:18pm UTC](https://community.shopify.dev/t/shopify-app-gem-database-lock-pile-ups-when-shopifys-token-endpoint-is-slow/39201/1 "2026-10-29T17:18:51Z")

</div>

Hi all,

We use shopify\_app with expiring offline tokens. When Shopify’s token endpoint degrades and starts responding in couple seconds instead of miliseconds, our database started backing up.

The reason is the token refresh in refresh\_token\_if\_expired!. It holds a row lock on the shop while it waits for Shopify to answer. While Shopify was slow, every other job for that shop waited on that lock. So did any insert into tables that reference the shop, such as webhook writes or any concurrent jobs for the same shop also stalled.

Has anyone else using the gem seen this when Shopify is degraded? How are you handling it?

Thanks!

I left out the [PR link](https://github.com/Shopify/shopify_app/pull/2094) and our fixes.
