TooTallNate / Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.
http://tootallnate.github.io/Java-WebSocket
MIT License
10.47k stars 2.57k forks source link

Fix issue #1418: WebSocketServer sometimes misses GET request after SSL handshake #1419

Closed robert-s-ubi closed 3 months ago

robert-s-ubi commented 3 months ago

Description

On Ubuntu 22.04 with Linux 6.5, it was observed that when the server gets the SSL records containing the client handshake finished message and the first HTTP GET request in ONE read operation, the latter SSL record is never processed.

Commit 89eaf410dd8fe3845fa6fb0de3469b55da0205cb should have fixed this, but it turned out that when SSLSocketChannel2#processHandshake() is called from SSLSocketChannel2#write(), the second SSL record containing the HTTP GET request is stashed away, but never retrieved, since the calling code in WebSocketServer#doWrite() has no provisions for this, only WebSocketServer#doRead() does.

Change SSLSocketChannel2#processHandshake() to only read from the socket when called from SSLSocketChannel#read(), to ensure that when two SSL records are read, the second one is processed as well.

Related Issue

Fixes #1418

Motivation and Context

Our integration tests which locally connect a WebSocketClient to a WebSocketServer were sporadically failing when run on Ubuntu 22.04 with Linux 6.5 (this never occurred in Ubuntu 20.04 with Linux 5.14).

With this change, the tests run reliably. We have verified from detailed java.net debug logs that when two SSL records are retrieved in one read, they are now both processed.

How Has This Been Tested?

Tested with our internal integration tests.

Types of changes

Checklist: