Skip to content

Commit df61e82

Browse files
author
Artem
committed
#RI-4436 close connection after import
1 parent 98c6701 commit df61e82

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

redisinsight/api/src/modules/bulk-actions/bulk-import.service.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
mockClientMetadata,
66
mockDatabaseConnectionService,
77
mockIORedisClient,
8-
mockIORedisCluster, MockType
8+
mockIORedisCluster, MockType,
99
} from 'src/__mocks__';
1010
import { MemoryStoredFile } from 'nestjs-form-data';
1111
import { BulkActionSummary } from 'src/modules/bulk-actions/models/bulk-action-summary';
@@ -195,6 +195,7 @@ describe('BulkImportService', () => {
195195
},
196196
duration: jasmine.anything(),
197197
});
198+
expect(mockIORedisClient.disconnect).toHaveBeenCalled();
198199
});
199200

200201
it('should throw an error in case of global error', async () => {
@@ -205,6 +206,7 @@ describe('BulkImportService', () => {
205206

206207
fail();
207208
} catch (e) {
209+
expect(mockIORedisClient.disconnect).not.toHaveBeenCalled();
208210
expect(e).toBeInstanceOf(NotFoundException);
209211
}
210212
});

redisinsight/api/src/modules/bulk-actions/bulk-import.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ export class BulkImportService {
8080

8181
let parseErrors = 0;
8282

83+
let client;
84+
8385
try {
84-
const client = await this.databaseConnectionService.createClient(clientMetadata);
86+
client = await this.databaseConnectionService.createClient(clientMetadata);
8587

8688
const stream = Readable.from(dto.file.buffer);
8789
let batch = [];
@@ -126,9 +128,12 @@ export class BulkImportService {
126128

127129
this.analyticsService.sendActionStopped(result);
128130

131+
client.disconnect();
132+
129133
return result;
130134
} catch (e) {
131135
this.logger.error('Unable to process an import file', e);
136+
client?.disconnect();
132137
throw wrapHttpError(e);
133138
}
134139
}

0 commit comments

Comments
 (0)