Skip to content

Commit d25b1a8

Browse files
committed
[client] Implement max number of retry to get infinite error bundle content
1 parent 741235e commit d25b1a8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pycti/utils/opencti_stix2.py

+15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
STIX_EXT_OCTI_SCO = "extension-definition--f93e2c80-4231-4f9a-af8b-95c9bd566a82"
4949
STIX_EXT_MITRE = "extension-definition--322b8f77-262a-4cb8-a915-1e441e00329b"
5050
PROCESSING_COUNT: int = 4
51+
MAX_PROCESSING_COUNT: int = 100
5152

5253
meter = metrics.get_meter(__name__)
5354
bundles_timeout_error_counter = meter.create_counter(
@@ -2489,6 +2490,20 @@ def import_item(
24892490
work_id: str = None,
24902491
):
24912492
worker_logger = self.opencti.logger_class("worker")
2493+
# Ultimate protection to avoid infinite retry
2494+
if processing_count > MAX_PROCESSING_COUNT:
2495+
if work_id is not None:
2496+
item_str = json.dumps(item)
2497+
self.opencti.work.report_expectation(
2498+
work_id,
2499+
{
2500+
"error": "Max number of retries reached, please see error logs of workers for more details",
2501+
"source": (
2502+
item_str if len(item_str) < 50000 else "Bundle too large"
2503+
),
2504+
},
2505+
)
2506+
return False
24922507
try:
24932508
self.opencti.set_retry_number(processing_count)
24942509
opencti_operation = self.opencti.get_attribute_in_extension(

0 commit comments

Comments
 (0)