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

Attempt to write a response log when flushBuffer() fails #1997

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kasmarian
Copy link
Member

@kasmarian kasmarian commented Jan 6, 2025

Description

In cases when a reactive client closes a connection, flushBuffer() operation may throw a "java.io.IOException: Broken pipe" exception, that in its own turn leads to a connection close, and LogbookAsyncListener.onComplete call. But as this happens AFTER ServletResponse.freeResources() is called (by HttpServerExchange.endExchange() in case of undertow, for example), the responseWritingStageSynchronizationName attribute is not present anymore in the response object, which leads to an NPE. This fix attempts to overcome this edge case, by trying to write the response anyway, even after the flush fails.

I wasn't able to add a reproducible unit test with MockMvc for this use case so far, but added an isolated one. Any suggestions are welcome

Motivation and Context

#1963

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

In cases when a reactive client closes a connection, flushBuffer() operation may throw a "java.io.IOException: Broken pipe" exception, that in its own turn leads to a connection close, and `LogbookAsyncListener.onComplete` call. But as this happens AFTER `ServletResponse.freeResources()` is called (by HttpServerExchange.endExchange() in case of undertow, for example), the `responseWritingStageSynchronizationName` attribute is not present anymore in the response object, which leads to an NPE.
This fix attempts to overcome this edge case, by trying to write the response anyway, even after the flush fails.
@kasmarian kasmarian added the bugfix Bug fixes and patches label Jan 6, 2025
@msdousti
Copy link
Collaborator

msdousti commented Jan 6, 2025

I suggest having a mock-based test to reproduce the NPE, in order to quench the thirst for 100% coverage.

@kasmarian
Copy link
Member Author

I suggest having a mock-based test to reproduce the NPE, in order to quench the thirst for 100% coverage.

added the test in 12c63a7 ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Bug fixes and patches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants