You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brief Description of the Bug
Hi, we use NextJS deployed on Docker and with Kubernetes and we use this package with the redis-string example as it is recommended in the NextJS docs to use another cache configuration when using kubernetes.
When a second kubernetes pod is spawned the memory of the first pod is copied, and as such the redis client connection too.
And as soon as the second pod starts to talk to redis I get a Socket already opened and the pod crashes because it tried to use the same connection socket as the first.
I don't really know if it's the responsibility of this package to solve this but maybe you can help me.
Basically we would need a way to create a new connection if a new pod spawn, because the connection — if I understand correctly — is only initiated once when the NextJS process starts.
Thanks.
Severity
Major
Frequency of Occurrence
Always (when a second pod spawn)
Steps to Reproduce Complicated...
Expected vs. Actual Behavior
A way to create another connection when a pod starts
I have found that if your Redis server is unreachable during the building process, Redis will throw an Socket already opened error. Please also check if this is the root of the issue.
@rutwik-fale-amla, it is possible that your app is falling back to the local-lru Handler. If this is the case, let's continue communicating.
Please check if your app works with the redis-stack Handler by adding NEXT_PRIVATE_DEBUG_CACHE=1 to your .env file. You should see the following log in your stdout: get from "redis-stack" ....
Activity
ezeparziale commentedon Dec 22, 2023
Check your Redis config if you have any limit on connections.
I have Kubernetes set up with two pods running Next.js and one pod running Redis, and I don't encounter any problems with connections.
better-salmon commentedon Dec 22, 2023
Hey, @AlexisWalravens! I can’t but agree that the steps to reproduce is complicated. But maybe this dead simple solution might help.
Before all, update the
@neshca/cache-handlerto the latest version,0.6.2, at the time of writing.Then, add
NEXT_PRIVATE_DEBUG_CACHE=1to your.envfile during the debugging.After these steps, add the following check to your
onCreationhook:Write back if it helps!
better-salmon commentedon Dec 22, 2023
I have found that if your Redis server is unreachable during the building process, Redis will throw an
Socket already openederror. Please also check if this is the root of the issue.AlexisWalravens commentedon Dec 24, 2023
Hey !
@ezeparziale I don't think it's the connection limit since it's already used by another service I just added NextJS to it. But I'll make sure thanks!
@better-salmon I will also try this solution, but I will not able to test it until early January as it a work project and I'm on holiday until then.
Will let you know!
rutwik-fale-amla commentedon Dec 26, 2023
I was also encountering the same issue. By using @better-salmon workaround it get resolved.
Thank you!
better-salmon commentedon Dec 26, 2023
@rutwik-fale-amla, it is possible that your app is falling back to the
local-lruHandler. If this is the case, let's continue communicating.Please check if your app works with the
redis-stackHandler by addingNEXT_PRIVATE_DEBUG_CACHE=1to your.envfile. You should see the following log in your stdout:get from "redis-stack" ....rutwik-fale-amla commentedon Dec 26, 2023
@better-salmon, I have checked by adding NEXT_PRIVATE_DEBUG_CACHE=1 in the .env file and getting the following log.
"cache-handler-redis" is the name of the cache handler file.
rutwik-fale-amla commentedon Dec 26, 2023
@better-salmon
This is my cache handler