Skip to content

Catch exception when EventSender stopped #1248

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

Merged
merged 2 commits into from
Sep 16, 2020

Conversation

Z-Beatles
Copy link
Contributor

org.springframework.amqp.rabbit.logback.AmqpAppender.java

protected class EventSender implements Runnable {
	@Override
	public void run() {
		try {
			RabbitTemplate rabbitTemplate = new RabbitTemplate(AmqpAppender.this.connectionFactory)
			while (true) {
				final Event event = AmqpAppender.this.events.take();

				MessageProperties amqpProps = prepareMessageProperties(event);

				String routingKey = AmqpAppender.this.routingKeyLayout.doLayout(event.getEvent());

				sendOneEncoderPatternMessage(rabbitTemplate, routingKey);

				doSend(rabbitTemplate, event, event.getEvent(), name, amqpProps, routingKey);
			}
		}
		catch (InterruptedException e) {
			Thread.currentThread().interrupt();
		}
	}
}
...

Any exceptions in this while(true){} code block will be lost (except InterruptedException).

For example, when sending a message using a custom LoggingLayout to encodeMessage, any exceptions thrown from doLayout() will not be caught. The sending thread will stop and we have no way of knowing what went wrong.

@pivotal-issuemaster
Copy link

@Z-Beatles Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@Z-Beatles Thank you for signing the Contributor License Agreement!

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Any chances to have some test-case on the matter?
Thanks

@Z-Beatles
Copy link
Contributor Author

I have tried to provide a test-case but it affects other test-case. The problem is as I described, EventSender-thread missing catch exception. Hope to get help.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

I'm OK with the fix then since we need to release today.

@garyrussell , WDYT?

@garyrussell garyrussell merged commit 25ae5f3 into spring-projects:master Sep 16, 2020
garyrussell pushed a commit that referenced this pull request Sep 16, 2020
* Catch exception when EventSender stopped

* Add author
@Z-Beatles Z-Beatles deleted the fix branch September 19, 2020 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants