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

Add some debug output. #1639

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
27 changes: 24 additions & 3 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,10 @@
*/
declare databaseCollation: Collation | undefined;

private onSocketError: (error: Error) => void;
private onSocketClose: () => void;
private onSocketEnd: () => void;

/**
* Note: be aware of the different options field:
* 1. config.authentication.options
Expand Down Expand Up @@ -1742,6 +1746,10 @@

this.state = this.STATE.INITIALIZED;

this.onSocketError = (error: Error) => { this.socketError(error); };
this.onSocketClose = () => { this.socketClose(); };
this.onSocketEnd = () => { this.socketEnd(); };

this._cancelAfterRequestSent = () => {
this.messageIo.sendMessage(TYPE.ATTENTION);
this.createCancelTimer();
Expand All @@ -1756,16 +1764,25 @@
if (connectListener) {
const onConnect = (err?: Error) => {
this.removeListener('error', onError);
this.removeListener('end', onEnd);
connectListener(err);
};

const onError = (err: Error) => {
this.removeListener('connect', onConnect);
this.removeListener('end', onEnd);
connectListener(err);
};

const onEnd = () => {
this.removeListener('connect', onConnect);
this.removeListener('error', onError);
connectListener(new Error('unexpected connection end during connect'));

Check warning on line 1780 in src/connection.ts

View check run for this annotation

Codecov / codecov/patch

src/connection.ts#L1778-L1780

Added lines #L1778 - L1780 were not covered by tests
}

Check failure on line 1781 in src/connection.ts

View workflow job for this annotation

GitHub Actions / Linting

Missing semicolon

this.once('connect', onConnect);
this.once('error', onError);
this.once('end', onEnd);
}

this.transitionTo(this.STATE.CONNECTING);
Expand Down Expand Up @@ -1992,9 +2009,9 @@
}

socketHandlingForSendPreLogin(socket: net.Socket) {
socket.on('error', (error) => { this.socketError(error); });
socket.on('close', () => { this.socketClose(); });
socket.on('end', () => { this.socketEnd(); });
socket.on('error', this.onSocketError);
socket.on('close', this.onSocketClose);
socket.on('end', this.onSocketEnd);
socket.setKeepAlive(true, KEEP_ALIVE_INITIAL_DELAY);

this.messageIo = new MessageIO(socket, this.config.options.packetSize, this.debug);
Expand Down Expand Up @@ -3395,6 +3412,8 @@
if (handler.loginAckReceived) {
if (handler.routingData) {
this.routingData = handler.routingData;

console.log('socket closed before rerouting?', this.socket?.closed);
this.transitionTo(this.STATE.REROUTING);
} else {
this.transitionTo(this.STATE.LOGGED_IN_SENDING_INITIAL_SQL);
Expand Down Expand Up @@ -3446,6 +3465,7 @@
if (handler.loginAckReceived) {
if (handler.routingData) {
this.routingData = handler.routingData;
console.log('socket closed before rerouting?', this.socket?.closed);

Check warning on line 3468 in src/connection.ts

View check run for this annotation

Codecov / codecov/patch

src/connection.ts#L3468

Added line #L3468 was not covered by tests
return this.transitionTo(this.STATE.REROUTING);
} else {
return this.transitionTo(this.STATE.LOGGED_IN_SENDING_INITIAL_SQL);
Expand Down Expand Up @@ -3512,6 +3532,7 @@
if (handler.loginAckReceived) {
if (handler.routingData) {
this.routingData = handler.routingData;
console.log('socket closed before rerouting?', this.socket?.closed);
this.transitionTo(this.STATE.REROUTING);
} else {
this.transitionTo(this.STATE.LOGGED_IN_SENDING_INITIAL_SQL);
Expand Down
Loading