READONLY You can't write against a read-only replica

Hello,

After failover, I am receiving the "READONLY You can't write against a read-only replica" error in my Amazon ElastiCache for Redis (cluster mode disabled) cluster. This usually happens during the maintenance window. I'm using the primary endpoint.

If it might be the issue that StackExchange Redis cache DNS in the application node and routes traffic to the old primary node? How to handle such errors in this situation?

Thank you for