bbc / sqs-consumer

Build Amazon Simple Queue Service (SQS) based applications without the boilerplate
https://bbc.github.io/sqs-consumer/
Other
1.71k stars 330 forks source link

Allow consumers stopped with abort: true to be restarted #429

Closed adamrensel-artera closed 8 months ago

adamrensel-artera commented 8 months ago

Resolves https://github.com/bbc/sqs-consumer/issues/389

Description: This bug was originally closed, but I've been running into a related issue. Basically we want to start and stop a consumer based on a feature flag while using the abort option on .stop. The singleton AbortController makes it impossible to restart an aborted consumer, even if the consumer is recreated. This results in the abort signal persisting and being sent into any following AWS SDK calls.

This PR creates a new AbortController each time the consumer is started, which results in a fresh abort signal and allows the consumer to restart. I've also removed the previous controller.ts file as it's no longer used.

I've also added an associated test that fails without these changes that demonstrates how the abort signal is being passed to the AWS SDK .send method. Thanks!

Type of change:

Why is this change required?: A simple explanation of what the problem is and how this PR solves it

Code changes:


Checklist:

github-actions[bot] commented 8 months ago

CLA Assistant Lite bot CLA CHECK All Contributors have signed the CLA

adamrensel-artera commented 8 months ago

I have read the CLA Document and I hereby sign the CLA

adamrensel-artera commented 8 months ago

recheck

nicholasgriffintn commented 8 months ago

Thanks for the PR, it's appreciated, I'll take a look at this by Monday.

codeclimate[bot] commented 8 months ago

Code Climate has analyzed commit 3926fb69 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (80% is the threshold).

This pull request will bring the total coverage in the repository to 96.9% (0.0% change).

View more on Code Climate.

nicholasgriffintn commented 8 months ago

Released as v7.4.0-canary.0, we'll be testing that version and then release it as 7.4.0 once we're happy with the changes.