Skip to content

Support nonblocking writing to Jetty Websocket with possibility to assign callback [SPR-15527] #20086

@spring-projects-issues

Description

@spring-projects-issues

Askar Ibragimov opened SPR-15527 and commented

Jetty websocket server has two ways to send messages:

Presently Spring Websocket uses blocking write in Jetty adapter. Which means that the message engine of Spring (ExecutorSubscribableChannel) has to have many threads and a thread remains parked till client acknowledges the reception of message.

There are few issues with this approach

  • If client never acknowledges the reception on TCP level, the thread (from TaskExecutorChannel's threadpool) remains blocked. Actually due to a very funny decision of Jetty engineers to not set a timeout on these connections, so the block is never lifted (WebSocket hangs in blockingWrite jetty/jetty.project#272). In plain language, any Spring+Jetty app is exposed to a DDOS attack.
  • This is a bad utilization of threads. I might want to write a logic that re-uses the thread for something else and just get notified via callback when web socket processed the message. This would allow me to have smaller thread pools and truly high-load-ready nonblocking architecture.

Suggested improvement
Permit in Spring usage of non-blockig websocket write with possibility to expose respective callback or future on upper level. Then custom or new ExecutorChannel implementation may use these callbacks to smartly utilize smaller number of threads and do not have blocked threads.

Useful contribution from Jetty people (caveats of using non blocking API of Jetty) http://stackoverflow.com/questions/43257736/make-websocket-sending-non-blocking


Issue Links:

Referenced from: commits 1b0e95d

1 votes, 3 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by anothertype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions