Skip to content

When using a logging library associated with SLF4J to handle IOException of SseEmitter, the same exception for NIO cannot be caught. #35939

@setruth

Description

@setruth

Detailed description

During simulated heartbeat sending, when trying to catch IOExceptions in the SseEmiter.send operation, I found that while I could catch IOExceptions that occurred when the client disconnected, the same IOException was still thrown on the NIO thread. I understand this is NIO behavior; asynchronous operations cannot be caught on different threads. However, what I don't understand is that when I use the SLF4J logging library for logging output in the captured code block, the NIO logs are still printed. But when I don't use a logging library for output (e.g., using the print function), or don't perform any operation, the NIO logs are not printed. Why is this? I can't understand why the NIO logs are being printed, which prevents me from better handling this problem.

Use version

  • springboot : 3.5.6
  • jdk: 17

Reproduction Test

Image
  1. When I use curl http://localhost:8180/none-log to test none-log, it does not print the NIO IOException log.
  2. When I use curl http://localhost:8180/use-log to test use-log, it can capture errors, but it also prints NIO IOException logs.

Test Demo Repository

https://github.com/setruth/sse-exception

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions