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

Assert queues are all the same type in setQueueNames so applications … #1001

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

internetstaff
Copy link

…fail to start rather than throwing endless Executor errors.

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

This asserts there's not a mix of FIFO and non-FIFO queues earlier in SqsMessageListenerContainer.setQueueNames instead of waiting for the container to fail on startup.

💡 Motivation and Context

Migrating from 2.x, we had an @SqsListener with a mix of queue types. Instead of failing at startup, there's only one line logged:

s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'io.awspring.cloud.messaging.internalEndpointRegistryBeanName'

... followed by an endless loop of AWS SDK executor not accepting a task errors from all queues.

This is probably not an ideal fix - it seems like any failure in io.awspring.cloud.sqs.listener.DefaultListenerContainerRegistry#start should be fatal rather than leaving queues in a weird half-started state. I didn't go that deeply. Feel free to chuck this for a wider fix. :)

💚 How did you test it?

Added a simple UT, then pulled the SNAPSHOT into the application with the issue. Verified the app failed immediately with a very clear error.

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • I updated reference documentation to reflect the change
  • All tests passing
  • No breaking changes

🔮 Next steps

@tomazfernandes
Copy link
Contributor

Hi @internetstaff, sorry for the long delay. Your proposal sounds reasonable.

it seems like any failure in io.awspring.cloud.sqs.listener.DefaultListenerContainerRegistry#start should be fatal

I'm not sure I follow - as far as I'm aware if a container throws at startup, the app won't start up. So with the change you're proposing I believe it should prevent the app from starting up? What am I missing?

Thanks.

@Override
public void setQueueNames(Collection<String> queueNames) {
super.setQueueNames(queueNames);
assertAllQueuesSameType();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to check this in two places, how about we only check it here on setQueueNames and do that before calling super?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and confirmed this still resolves the issue for me.

@tomazfernandes tomazfernandes added the status: waiting-for-feedback Waiting for feedback from issuer label Mar 9, 2024
…fail to start rather than throwing endless Executor errors.
@internetstaff
Copy link
Author

I'm not sure I follow - as far as I'm aware if a container throws at startup, the app won't start up. So with the change you're proposing I believe it should prevent the app from starting up? What am I missing?

Sorry for the delay - I had to fire this back up myself. :)

What I see with this condition is that I do get "Application run failed" but the application doesn't shut down. Instead, it stays in a zombie state.

With this change, it logs the error and shuts down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants