openresty / stream-lua-nginx-module

Embed the power of Lua into NGINX TCP/UDP servers
BSD 2-Clause "Simplified" License
729 stars 198 forks source link

bugfix: `setkeepalive` failure on TLSv1.3 #361

Closed catbro666 closed 2 months ago

catbro666 commented 2 months ago

porting https://github.com/openresty/lua-nginx-module/pull/2356

When TLSv1.3 is used, the server may send a NewSessionTicket message after the handshake. While this message is ssl-layer data, tcpsock:sslhandshake does not consume it.

In the implementation of setkeepalive, recv is used to confirm the connection is still open and there is no unread data in the buffer. But it treats the NewSessionTicket message as application layer data and then setkeepalive fails with this error connection in dubious state.

In fact we don't need to peek here, because if the application data is read successfully then the connection is going to be closed anyway. Therefore, c->recv can be used instead which will consume the ssl-layer data implicitly.