spring-cloud-aws icon indicating copy to clipboard operation
spring-cloud-aws copied to clipboard

Classloader issue when using DevTools

Open rajadilipkolli opened this issue 2 years ago • 4 comments

Type: Bug

Component: SQS

Describe the bug MappingJackson2MessageConverter is not used when using SQSTemplate to send message as an object and receive using @SQSListener

However, when sending the message as converted json string it is working as expected

Sample

sqs contains simple implementation of using SQS.

It is working when I explicitly convert to json like here, Expect it to work when sent as the object payload.

rajadilipkolli avatar Feb 03 '23 10:02 rajadilipkolli

Thanks @rajadilipkolli, looking into it!

tomazfernandes avatar Feb 03 '23 10:02 tomazfernandes

This is a known issue with Spring Dev Tools - remove it and everything will work as expected.

The specific problem is we have a SQSMessagePayload class loaded by the AppClassloader, and the same class loaded by the RestartClassloader. When we get to targetPayloadType.isInstance(payload) in MessageMethodArgumentResolver, it returns false and tries to deserialize the payload again, which then breaks.

This issue is documented here and a couple other issues.

They propose a workaround which is documented here, but I couldn't get it to work - probably my fault. Maybe @rajadilipkolli can give it a shot?

In this answer, @garyrussell explains a similar problem in Spring Kafka.

When you send the payload already serialized, the type information added to the header is String, and so the payload will only get deserialized right before the method invocation, which makes it not available e.g. for interceptors and error handlers.

We could look into some workarounds e.g. not adding the type header when sending the message, but overall I don't think it'd be worth it changing production code in order to DevTools to work.

All that being said, I personally don't have that much experience with DevTools, if anyone wants to pitch in please do so.

@rajadilipkolli, what do you think?

tomazfernandes avatar Feb 03 '23 11:02 tomazfernandes

@tomazfernandes , Will check and let you know.. As far as I know @maciejwalkowiak also faced similar issue for dynamodb project

rajadilipkolli avatar Feb 03 '23 12:02 rajadilipkolli

Hi @tomazfernandes, after commenting dev tools dependency it is working as expected. I'm working on playing with devtools exclusions and inclusions, once successful will update here.

rajadilipkolli avatar Feb 06 '23 15:02 rajadilipkolli