Skip to content
Merged
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
21 changes: 14 additions & 7 deletions mysql/lib/mysql_error_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class MySQLErrorHandler implements ErrorHandler {
private unexpectedError: Error | null = null;
protected static readonly SYNTAX_ERROR_CODES = ["42000", "42S02"];
protected static readonly SYNTAX_ERROR_MESSAGE = "You have an error in your SQL syntax";
protected isNoOpListenerAttached = false;
protected isTrackingListenerAttached = false;

protected noOpListener(error: any) {
// Ignore the received error.
Expand Down Expand Up @@ -80,27 +82,32 @@ export class MySQLErrorHandler implements ErrorHandler {
}

attachErrorListener(clientWrapper: ClientWrapper | undefined): void {
if (!clientWrapper || !clientWrapper.client) {
if (!clientWrapper || !clientWrapper.client || this.isTrackingListenerAttached) {
return;
}
this.unexpectedError = null;
clientWrapper.client.removeListener("error", this.noOpListener);
clientWrapper.client.on("error", this.trackingListener);
clientWrapper.client.connection.removeListener("error", this.noOpListener);
this.isNoOpListenerAttached = false;
clientWrapper.client.connection.on("error", this.trackingListener);
this.isTrackingListenerAttached = true;
}

attachNoOpErrorListener(clientWrapper: ClientWrapper | undefined): void {
if (!clientWrapper || !clientWrapper.client) {
if (!clientWrapper || !clientWrapper.client || this.isNoOpListenerAttached) {
return;
}
clientWrapper.client.removeListener("error", this.trackingListener);
clientWrapper.client.on("error", this.noOpListener);
clientWrapper.client.connection.removeListener("error", this.trackingListener);
this.isTrackingListenerAttached = false;
clientWrapper.client.connection.on("error", this.noOpListener);
this.isNoOpListenerAttached = true;
}

removeErrorListener(clientWrapper: ClientWrapper | undefined): void {
if (!clientWrapper || !clientWrapper.client) {
return;
}

clientWrapper.client.removeListener("error", this.trackingListener);
clientWrapper.client.connection.removeListener("error", this.trackingListener);
this.isTrackingListenerAttached = false;
}
}
11 changes: 9 additions & 2 deletions pg/lib/abstract_pg_error_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export abstract class AbstractPgErrorHandler implements ErrorHandler {
protected unexpectedError: Error | null = null;
protected static readonly SYNTAX_ERROR_CODE = "42601";
protected static readonly SYNTAX_ERROR_MESSAGE = "syntax error";
protected isNoOpListenerAttached = false;
protected isTrackingListenerAttached = false;

abstract getNetworkErrors(): string[];

Expand Down Expand Up @@ -84,20 +86,24 @@ export abstract class AbstractPgErrorHandler implements ErrorHandler {
}

attachErrorListener(clientWrapper: ClientWrapper | undefined): void {
if (!clientWrapper || !clientWrapper.client) {
if (!clientWrapper || !clientWrapper.client || this.isTrackingListenerAttached) {
return;
}
this.unexpectedError = null;
clientWrapper.client.removeListener("error", this.noOpListener);
this.isNoOpListenerAttached = false;
clientWrapper.client.on("error", this.trackingListener);
this.isTrackingListenerAttached = true;
}

attachNoOpErrorListener(clientWrapper: ClientWrapper | undefined): void {
if (!clientWrapper || !clientWrapper.client) {
if (!clientWrapper || !clientWrapper.client || this.isNoOpListenerAttached) {
return;
}
clientWrapper.client.removeListener("error", this.trackingListener);
this.isTrackingListenerAttached = false;
clientWrapper.client.on("error", this.noOpListener);
this.isNoOpListenerAttached = true;
}

removeErrorListener(clientWrapper: ClientWrapper | undefined): void {
Expand All @@ -106,5 +112,6 @@ export abstract class AbstractPgErrorHandler implements ErrorHandler {
}

clientWrapper.client.removeListener("error", this.trackingListener);
this.isTrackingListenerAttached = false;
}
}