Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Build never finishes when using Redis for cache #7347

Open
1 task
ched-dev opened this issue Jan 14, 2023 · 1 comment
Open
1 task

[Bug?]: Build never finishes when using Redis for cache #7347

ched-dev opened this issue Jan 14, 2023 · 1 comment
Labels
bug/needs-info More information is needed for reproduction

Comments

@ched-dev
Copy link
Contributor

ched-dev commented Jan 14, 2023

What's not working?

After adding a Redis cache with yarn rw setup cache redis, whenever I try to run a yarn rw build, it will hang after the prerendering. The build never finishes and no errors are thrown.

How do we reproduce the bug?

  • Spin up a new application with Redwood 7.0.6 and some prerendered routes
  • Run a yarn rw build to confirm successful build
  • Follow the documentation for adding a Redis cache with yarn rw setup cache redis
  • You will have a /api/src/lib/cache.ts file similar to:
import {
  createCache,
  InMemoryClient,
  RedisClient,
} from '@redwoodjs/api/cache'

import { logger } from './logger'

export let client: InMemoryClient | RedisClient

if (process.env.NODE_ENV === 'test') {
  client = new InMemoryClient()
} else {
  try {
    client = new RedisClient({ url: process.env.CACHE_HOST, logger })
  } catch (e) {
    logger.error(`Could not connect to cache: ${e.message}`)
  }
}

export const { cache, cacheFindMany, cacheClient, deleteCacheKey } = createCache(client, {
  logger,
  timeout: 500,
})
  • Run a yarn rw build which will hang after the prerendering and never finish

Simple fix

  • In your /api/src/lib/cache.ts file, update the following line:
- if (process.env.NODE_ENV === 'test') {
+ if (process.env.NODE_ENV === 'test' || process.env.__REDWOOD__PRERENDERING === '1') {
  • Run a yarn rw build and it should finish successfully

What's your environment? (If it applies)

  System:
    OS: macOS 12.0.1
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 20.11.1 - /private/var/folders/.../node
    Yarn: 3.2.0 - /private/var/folders/.../yarn
  Databases:
    SQLite: 3.36.0 - /usr/bin/sqlite3
  Browsers:
    Chrome: 123.0.6312.87
    Safari: 15.1
  npmPackages:
    @redwoodjs/auth-dbauth-setup: 7.0.6 => 7.0.6
    @redwoodjs/core: 7.0.6 => 7.0.6

Are you interested in working on this?

  • I'm interested in working on this
@ched-dev ched-dev added the bug/needs-info More information is needed for reproduction label Jan 14, 2023
@ched-dev
Copy link
Contributor Author

ched-dev commented Mar 29, 2024

Update:
I have updated the info in the ticket for the latest version of RedwoodJS I am using now, 7.0.6. I am still experiencing this problem.

I have also submitted #10372 which once resolved, a fix for this could be created by adjusting the generated cache.ts code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/needs-info More information is needed for reproduction
Projects
None yet
Development

No branches or pull requests

1 participant