next-drupal
                                
                                 next-drupal copied to clipboard
                                
                                    next-drupal copied to clipboard
                            
                            
                            
                        getPathsFromContext() with multiple types prone to deadlocks
I'm getting following exception fairly consistently when visiting any of the node pages:
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 5 database is locked: INSERT INTO "oauth2_token" ("bundle", "uuid", "auth_user_id", "client", "value", "created", "changed", "expire", "status") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?); Array ( [0] => access_token [1] => ? [2] => ? [3] => ? [4] => ? [5] => ? [6] => ? [7] => ? [8] => ? ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->doSaveFieldItems() (line 940 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
This seems to be caused by how getPathsFromContext() is calling getResourceCollection() multiple times when multiple types are provided, leading into multiple calls for buildHeaders(). I haven't been able to reproduce this when calling getPathsFromContext() with a single type.
Reporting here instead of Simple OAuth since I haven't had a chance to research the root cause for this.
Is this resulting into multiple tokens creating when running yarn dev?
I've been looking for a solution for a while now. We implemented an in-memory cache + a larger value for the token expiry. This seems to be working for production.
On dev/build however, Next runs getStaticPaths and getStaticProps on different workers. The memory cache solution does not work here.
I'll continue looking into this and see if we can refactor the getPathsFromContext/getResourceCollection calls.
Just adding some thoughts here...
I'm wondering if we even need authenticated requests for getStaticPaths? Static pages are always non-authenticated.
Authenticated calls are used for rendering unpublished content and revisions in the preview which is a server-side call in getStaticProps with fallback: blocking.
So do we need to make auth'd call for getStaticPaths? 🤔
\cc @robdecker ^^
Is this resulting into multiple tokens creating when running
yarn dev?
I've been running into this error when running yarn build as well
@harumijang Are you using the DrupalClient? How big is your site (as in how many content types or pages?)
Using DrupalClient and very small demo site with 5 pages. But I was able to get around the error by reinstalling my backend with mySQL instead of SQlite.
OK. Good to know. Let me know if you hit this issue again.