Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Include connectionRetryCount to Reporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
İbrahim Gürses committed Jul 22, 2019
1 parent a18d958 commit 99d37ed
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class Reporter {
private config: ThundraConfig;
private useHttps: boolean;
private requestOptions: http.RequestOptions;
private connectionRetryCount: number;

constructor(config: ThundraConfig, u?: url.URL) {
this.reports = [];
this.config = config ? config : new ThundraConfig({});
this.useHttps = (u ? u.protocol : URL.protocol) === 'https:';
this.requestOptions = this.createRequestOptions();
this.connectionRetryCount = 0;
}

createRequestOptions(u?: url.URL): http.RequestOptions {
Expand Down Expand Up @@ -134,14 +136,21 @@ class Reporter {
});

await Promise.all(reportPromises).catch(async (err) => {
if (err.code === 'ECONNRESET') {
if (this.connectionRetryCount === 0 && err.code === 'ECONNRESET') {
ThundraLogger.getInstance().debug(
'Keep Alive connection reset by server. Will send monitoring data again.');

this.connectionRetryCount++;

await this.sendReports();
this.connectionRetryCount = 0;
return;
}

ThundraLogger.getInstance().error(err);
});

this.connectionRetryCount = 0;
}

request(batch: any[]): Promise<any> {
Expand Down

0 comments on commit 99d37ed

Please sign in to comment.