Skip to content

fix(rest): handle broken pipe gracefully#4132

Merged
GMishx merged 1 commit intoeclipse-sw360:mainfrom
siemens:fix/io/aborted
May 7, 2026
Merged

fix(rest): handle broken pipe gracefully#4132
GMishx merged 1 commit intoeclipse-sw360:mainfrom
siemens:fix/io/aborted

Conversation

@GMishx
Copy link
Copy Markdown
Member

@GMishx GMishx commented May 7, 2026

Summary

This fix separates client-disconnect write failures (Broken pipe, AsyncRequestNotUsableException) from actual serialization failures in the REST exception handler, and improves server transfer tolerance for large JSON payloads.

Problem

Previously, when clients disconnected during response serialization, the server logged misleading 400/500 errors with full stacktraces as if they were application failures. This added noise to logs and masked real issues.

Solution

  1. Exception Classification: Added isClientAbortException() detector in RestExceptionHandler to identify client-abort patterns by cause chain inspection.
  2. Graceful Response Handling: For client aborts, return empty 204 No Content and log warning + debug details instead of attempting error body write.
  3. Transfer Tolerance: Enabled response compression and increased timeouts to reduce disconnect likelihood during large response serialization:
    • Gzip compression for JSON/HAL (min 2KB)
    • Tomcat connection timeout: 60s
    • Async request timeout: 120s
  4. Hardened Auth Entry Point: SimpleAuthenticationEntryPoint.commence() now gracefully handles client disconnects when writing 401 responses.

Changes

  • RestExceptionHandler.java: Added handlers for HttpMessageNotWritableException and AsyncRequestNotUsableException; added static client-abort detector.
  • SimpleAuthenticationEntryPoint.java: Hardened response writing with committed-response guard and client-abort exception handling.
  • application.yml: Enabled server compression and adjusted timeouts.
  • RestExceptionHandlerTest.java (new): Tests for broken-pipe detection and response behavior.

Testing

Run focused resource-server tests:

mvn -pl rest/resource-server -P deploy -Dbase.deploy.dir=/tmp test -DskipITs

Manual verification:

  • Check logs for "Client disconnected while writing response" (WARN) instead of "Broken pipe" (ERROR with stacktrace).
  • Verify large response endpoints continue to work without spurious 500 errors.

Checklist

  • All related issues are referenced (none — housekeeping fix)
  • Code generated with GitHub Copilot (assistant mode)
  • Unit tests added for new behavior
  • No new dependencies
  • EPL-2.0 license headers on new files

Classify client-abort write failures (Broken pipe,
AsyncRequestNotUsableException, ClientAbortException) separately from
real serialization failures in the global exception handler. For
client-abort cases, return empty 204 response and log with lower
severity (WARN + DEBUG details) instead of 500 ERROR + full stacktrace.

Improve transfer tolerance with:
- Response compression enabled for JSON/HAL/text media types
- Increased Tomcat connection timeout (60s)
- Increased async request timeout (120s)

Harden direct response writing in SimpleAuthenticationEntryPoint to
gracefully handle client disconnects when writing unauthorized responses

Add RestExceptionHandlerTest to validate client-abort vs real failure
behavior.

Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
@GMishx GMishx force-pushed the fix/io/aborted branch from 18543ce to f7f7392 Compare May 7, 2026 11:01
@GMishx GMishx merged commit bdfaa11 into eclipse-sw360:main May 7, 2026
3 checks passed
@GMishx GMishx deleted the fix/io/aborted branch May 7, 2026 11:25
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.

1 participant