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

[backend] Improve connection drop handling for importCSV connector (#6314) #6533

Merged
merged 2 commits into from
Apr 3, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import type { ConnectorConfig } from '../connector';
import { IMPORT_CSV_CONNECTOR } from './importCsv';
import { internalLoadById } from '../../database/middleware-loader';
import { DatabaseError } from '../../config/errors';

Check warning on line 16 in opencti-platform/opencti-graphql/src/connector/importCsv/importCsv-connector.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/connector/importCsv/importCsv-connector.ts#L16

Added line #L16 was not covered by tests

const RETRY_CONNECTION_PERIOD = 10000;

Expand Down Expand Up @@ -102,7 +103,13 @@

const handleCsvImport = async (context: AuthContext) => {
consumeQueue(context, connector.id, connectionSetterCallback, consumeQueueCallback).catch(() => {
if (rabbitMqConnection) rabbitMqConnection.close();
if (rabbitMqConnection) {
try {
rabbitMqConnection.close();
} catch (e) {
logApp.error(DatabaseError('Closing RabbitMQ connection failed', { cause: e }));
}
}

Check warning on line 112 in opencti-platform/opencti-graphql/src/connector/importCsv/importCsv-connector.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/connector/importCsv/importCsv-connector.ts#L106-L112

Added lines #L106 - L112 were not covered by tests
setTimeout(handleCsvImport, RETRY_CONNECTION_PERIOD);
});
};
Expand Down
5 changes: 5 additions & 0 deletions opencti-platform/opencti-graphql/src/database/rabbitmq.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@
reject(err);
} else { // Connection success
logApp.info('Starting connector queue consuming');
conn.on('close', (onConnectError) => {
if (onConnectError) {
reject(onConnectError);
}
});

Check warning on line 257 in opencti-platform/opencti-graphql/src/database/rabbitmq.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/database/rabbitmq.js#L253-L257

Added lines #L253 - L257 were not covered by tests
conn.on('error', (onConnectError) => {
reject(onConnectError);
});
Expand Down