-
-
Notifications
You must be signed in to change notification settings - Fork 18
refactor: improve Redis client connection handling and error management to prevent app shutdown #1449
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
refactor: improve Redis client connection handling and error management to prevent app shutdown #1449
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -458,7 +458,6 @@ export class DataAccessObjectRedis extends BasicDataAccessObject implements IDat | |||||
| try { | ||||||
| const redisClient = await this.getClient(); | ||||||
| const response = await redisClient.ping(); | ||||||
|
|
||||||
| if (response === 'PONG') { | ||||||
| return { | ||||||
| result: true, | ||||||
|
|
@@ -855,23 +854,51 @@ export class DataAccessObjectRedis extends BasicDataAccessObject implements IDat | |||||
| ? Number(this.connection.database) | ||||||
| : 0 | ||||||
| : 0; | ||||||
| if (!client) { | ||||||
| client = createClient({ | ||||||
| socket: { | ||||||
| try { | ||||||
| if (!client) { | ||||||
| const shouldUseTLS = this.connection.ssl !== false; | ||||||
|
|
||||||
| const socketConfig: any = { | ||||||
| host: this.connection.host, | ||||||
| port: this.connection.port, | ||||||
| ca: this.connection.cert || undefined, | ||||||
| cert: this.connection.cert || undefined, | ||||||
| rejectUnauthorized: this.connection.ssl === false ? false : true, | ||||||
| }, | ||||||
| password: this.connection.password || undefined, | ||||||
| username: this.connection.username || undefined, | ||||||
| database: database, | ||||||
| }); | ||||||
| await client.connect(); | ||||||
| LRUStorage.setRedisClientCache(this.connection, client); | ||||||
| reconnectStrategy: (retries: number) => { | ||||||
| if (retries > 3) { | ||||||
| return new Error('Max reconnection attempts reached'); | ||||||
|
||||||
| return new Error('Max reconnection attempts reached'); | |
| return false; |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for rejectUnauthorized is incorrect. When shouldUseTLS is true, this line will always evaluate to true because it checks this.connection.ssl === false (which is false when TLS is enabled).
The current logic:
- When
this.connection.ssl !== false(TLS enabled):rejectUnauthorized = false ? false : true→true - When
this.connection.ssl === false(TLS disabled): This block won't execute anyway
This should be simplified or corrected. Consider:
socketConfig.rejectUnauthorized = this.connection.ssl !== false;Or if you need explicit control over certificate validation, use a dedicated property rather than overloading the ssl boolean.
| socketConfig.rejectUnauthorized = this.connection.ssl === false ? false : true; | |
| socketConfig.rejectUnauthorized = this.connection.ssl !== false; |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using console.error for logging in a library/shared-code module is not ideal. Consider using a proper logging framework or allowing the error to bubble up through the existing error handling mechanism.
Additionally, the error handler removes the client from cache but doesn't handle the case where the client might be in an error state but still cached. This could lead to subsequent calls trying to use a failed client before it gets removed.
Consider either:
- Using a proper logger that's injected or configured for the application
- Emitting events that can be handled by application-level logging
- At minimum, making logging configurable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type annotation
anyforsocketConfigbypasses type safety. Consider using a proper type from the Redis client library or defining a specific interface for the socket configuration.For example: