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

Handle stream error in StandaloneConnector.js #1236

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/connectors/StandaloneConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export default class StandaloneConnector extends AbstractConnector {
} else {
this.stream = createConnection(connectionOptions);
}

this.stream.once("error", err => {
reject(err);
});
} catch (err) {
reject(err);
return;
Expand Down
Binary file added test/dump.rdb
Binary file not shown.
17 changes: 17 additions & 0 deletions test/functional/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@ describe("connection", function () {
done();
});
});

it("should reject on initial connection error", function (done) {
const stub = sinon
.stub(net.Socket.prototype, "connect")
.callsFake((options) => {
process.nextTick(function () {
net.Socket.prototype.emit.bind(net.Socket.prototype, "error");
});
});

const redis = new Redis({ lazyConnect: true });
redis.connect().catch(function () {
stub.restore();
redis.disconnect();
done();
});
});
});

describe("retryStrategy", function () {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/connectors/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("StandaloneConnector", () => {
});

it("ignore path when port is set and path is null", async () => {
const spy = sinon.stub(net, "createConnection");
const spy = sinon.stub(net, "createConnection").returns(new net.Socket());
const connector = new StandaloneConnector({ port: 6379, path: null });
await connector.connect(() => {});
expect(spy.calledOnce).to.eql(true);
Expand All @@ -29,7 +29,7 @@ describe("StandaloneConnector", () => {
});

it("supports tls", async () => {
const spy = sinon.stub(tls, "connect");
const spy = sinon.stub(tls, "connect").returns(new net.Socket());
const connector = new StandaloneConnector({
port: 6379,
tls: { ca: "on" },
Expand Down