Skip to content

Commit b70aa4e

Browse files
committedDec 9, 2021
fix for e112568 - should not retry connecting if failed due to wrong auth
1 parent ac808ea commit b70aa4e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed
 

‎packages/client/lib/client/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ScanCommandOptions } from '../commands/SCAN';
1111
import { HScanTuple } from '../commands/HSCAN';
1212
import { extendWithCommands, extendWithModulesAndScripts, LegacyCommandArguments, transformCommandArguments, transformCommandReply, transformLegacyCommandArguments } from '../commander';
1313
import { Pool, Options as PoolOptions, createPool } from 'generic-pool';
14-
import { ClientClosedError, DisconnectsClientError } from '../errors';
14+
import { ClientClosedError, DisconnectsClientError, AuthError } from '../errors';
1515
import { URL } from 'url';
1616
import { TcpSocketConnectOpts } from 'net';
1717

@@ -219,7 +219,9 @@ export default class RedisClient<M extends RedisModules, S extends RedisScripts>
219219
password: this.#options.password ?? ''
220220
}),
221221
{ asap: true }
222-
)
222+
).catch(err => {
223+
throw new AuthError(err.message);
224+
})
223225
);
224226
}
225227

‎packages/client/lib/client/socket.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as net from 'net';
33
import * as tls from 'tls';
44
import { encodeCommand } from '../commander';
55
import { RedisCommandArguments } from '../commands';
6-
import { ConnectionTimeoutError, ClientClosedError, SocketClosedUnexpectedlyError } from '../errors';
6+
import { ConnectionTimeoutError, ClientClosedError, SocketClosedUnexpectedlyError, AuthError } from '../errors';
77
import { promiseTimeout } from '../utils';
88

99
export interface RedisSocketCommonOptions {
@@ -110,6 +110,11 @@ export default class RedisSocket extends EventEmitter {
110110
} catch (err) {
111111
this.#socket.destroy();
112112
this.#socket = undefined;
113+
114+
if (err instanceof AuthError) {
115+
this.#isOpen = false;
116+
}
117+
113118
throw err;
114119
}
115120

‎packages/client/lib/errors.ts

+6
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ export class SocketClosedUnexpectedlyError extends Error {
3333
super('Socket closed unexpectedly');
3434
}
3535
}
36+
37+
export class AuthError extends Error {
38+
constructor(message: string) {
39+
super(message);
40+
}
41+
}

0 commit comments

Comments
 (0)
Please sign in to comment.