Skip to content

Commit 03734d0

Browse files
committed
TS-2709: ATS does not send close-notify on shutdown.
1 parent d41edbc commit 03734d0

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
-*- coding: utf-8 -*-
22
Changes with Apache Traffic Server 5.3.0
33

4+
*) [TS-2709] ATS does not send close-notify on shutdown. Confuses some clients.
5+
46
*) [TS-3467] Cleanup tmp files created from traffic_via tests.
57

68
*) [TS-3419] Run the source through clang-format. Keep it clean!

iocore/net/P_SSLNetVConnection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class SSLNetVConnection : public UnixNetVConnection
113113
virtual int64_t load_buffer_and_write(int64_t towrite, int64_t &wattempted, int64_t &total_written, MIOBufferAccessor &buf,
114114
int &needs);
115115
void registerNextProtocolSet(const SSLNextProtocolSet *);
116+
virtual void do_io_close(int lerrno = -1);
116117

117118
////////////////////////////////////////////////////////////
118119
// Instances of NetVConnection should be allocated //

iocore/net/SSLNetVConnection.cc

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,43 @@ SSLNetVConnection::SSLNetVConnection()
762762
{
763763
}
764764

765+
void
766+
SSLNetVConnection::do_io_close(int lerrno)
767+
{
768+
if (this->ssl != NULL && sslHandShakeComplete) {
769+
int new_shutdown_mode = 0, shutdown_mode = 0;
770+
if (this->lerrno < 0) {
771+
new_shutdown_mode = SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN;
772+
} else {
773+
shutdown_mode = SSL_get_shutdown(ssl);
774+
Debug("ssl-shutdown", "previous shutdown state 0x%x", shutdown_mode);
775+
new_shutdown_mode = shutdown_mode | SSL_RECEIVED_SHUTDOWN;
776+
}
777+
if (new_shutdown_mode != shutdown_mode) {
778+
// We do not need to sit around and wait for the client's close-notify if
779+
// they have not already sent it. We will still be standards compliant
780+
Debug("ssl-shutdown", "new SSL_set_shutdown 0x%x", new_shutdown_mode);
781+
SSL_set_shutdown(ssl, new_shutdown_mode);
782+
}
783+
784+
// If the peer has already sent a FIN, don't bother with the shutdown
785+
// They will just send us a RST for our troubles
786+
// This test is not foolproof. The client's fin could be on the wire
787+
// at the same time we send the close-notify. If so, the client will likely
788+
// send RST anyway
789+
char c;
790+
ssize_t x = recv(this->con.fd, &c, 1, MSG_PEEK);
791+
// x < 0 means error. x == 0 means fin sent
792+
if (x != 0) {
793+
// Send the close-notify
794+
int ret = SSL_shutdown(ssl);
795+
Debug("ssl-shutdown", "SSL_shutdown %s", (ret)?"success":"failed");
796+
}
797+
}
798+
// Go on and do the unix socket cleanups
799+
super::do_io_close(lerrno);
800+
}
801+
765802
void
766803
SSLNetVConnection::free(EThread *t)
767804
{
@@ -780,8 +817,6 @@ SSLNetVConnection::free(EThread *t)
780817
closed = 0;
781818
ink_assert(con.fd == NO_FD);
782819
if (ssl != NULL) {
783-
/*if (sslHandShakeComplete)
784-
SSL_set_shutdown(ssl, SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); */
785820
SSL_free(ssl);
786821
ssl = NULL;
787822
}

iocore/net/SSLUtils.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,6 @@ SSLInitServerContext(const SSLConfigParams *params, const ssl_user_config &sslMu
12381238
SSL_CTX_set_options(ctx, SSL_OP_SAFARI_ECDHE_ECDSA_BUG);
12391239
#endif
12401240

1241-
SSL_CTX_set_quiet_shutdown(ctx, 1);
1242-
12431241
// pass phrase dialog configuration
12441242
passphrase_cb_userdata ud(params, sslMultCertSettings.dialog, sslMultCertSettings.first_cert, sslMultCertSettings.key);
12451243

0 commit comments

Comments
 (0)