Summary
We're seeing an intermittent IllegalArgumentException
during HTTP response serialization using Spring Boot 3.4.2 on Kubernetes. The exact same image sometimes works perfectly, and other times fails with this error:
java.lang.IllegalArgumentException: getWriter() has already been called for this response
The exception occurs inside AbstractJackson2HttpMessageConverter.writeInternal(...)
, which is triggered via the standard message conversion flow when returning a response entity. (.java#L438)
This does not appear to be a race condition in our own code, and we can't consistently reproduce it — but it happens often enough to be problematic (3–4 out of every 10 pod startups).
Stack Trace (Simplified)
The flow leading to the exception looks like this:
HttpEntityMethodProcessor.writeWithMessageConverters(...)
→ AbstractMessageConverterMethodProcessor (switching converter)
→ MappingJackson2HttpMessageConverter.write(...) [GENERIC]
→ AbstractGenericHttpMessageConverter.write(...)
→ AbstractJackson2HttpMessageConverter.writeInternal(...) ←