@@ -129,41 +129,41 @@ void HTTPSConnection::closeConnection() {
129
129
// Set the connection state to closing. We stay in closing as long as SSL has not been shutdown
130
130
// correctly
131
131
_connectionState = STATE_CLOSING;
132
+ }
132
133
133
- // Try to tear down SSL
134
- if (_ssl) {
135
- if (SSL_shutdown (_ssl) == 0 ) {
136
- // SSL_shutdown will return 1 as soon as the client answered with close notify
137
- // This means we are safe to close the socket
138
- SSL_free (_ssl);
139
- _ssl = NULL ;
140
- } else if (_shutdownTS + HTTPS_SHUTDOWN_TIMEOUT < millis ()) {
141
- // The timeout has been hit, we force SSL shutdown now by freeing the context
142
- SSL_free (_ssl);
143
- _ssl = NULL ;
144
- HTTPS_DLOG (" [ERR] SSL_shutdown did not receive close notification from the client" );
145
- _connectionState = STATE_ERROR;
146
- }
134
+ // Try to tear down SSL while we are in the _shutdownTS timeout period or if an error occurred
135
+ if (_ssl) {
136
+ if (_connectionState == STATE_ERROR || SSL_shutdown (_ssl) == 0 ) {
137
+ // SSL_shutdown will return 1 as soon as the client answered with close notify
138
+ // This means we are safe to close the socket
139
+ SSL_free (_ssl);
140
+ _ssl = NULL ;
141
+ } else if (_shutdownTS + HTTPS_SHUTDOWN_TIMEOUT < millis ()) {
142
+ // The timeout has been hit, we force SSL shutdown now by freeing the context
143
+ SSL_free (_ssl);
144
+ _ssl = NULL ;
145
+ HTTPS_DLOG (" [ERR] SSL_shutdown did not receive close notification from the client" );
146
+ _connectionState = STATE_ERROR;
147
147
}
148
+ }
148
149
149
- // If SSL has been brought down, close the socket
150
- if (!_ssl) {
151
- // Tear down the socket
152
- if (_socket >= 0 ) {
153
- HTTPS_DLOGHEX (" [<--] Connection has been closed. fid = " , _socket);
154
- close (_socket);
155
- _socket = -1 ;
156
- _addrLen = 0 ;
157
- }
150
+ // If SSL has been brought down, close the socket
151
+ if (!_ssl) {
152
+ // Tear down the socket
153
+ if (_socket >= 0 ) {
154
+ HTTPS_DLOGHEX (" [<--] Connection has been closed. fid = " , _socket);
155
+ close (_socket);
156
+ _socket = -1 ;
157
+ _addrLen = 0 ;
158
+ }
158
159
159
- if (_connectionState != STATE_ERROR) {
160
- _connectionState = STATE_CLOSED;
161
- }
160
+ if (_connectionState != STATE_ERROR) {
161
+ _connectionState = STATE_CLOSED;
162
+ }
162
163
163
- if (_httpHeaders != NULL ) {
164
- delete _httpHeaders;
165
- _httpHeaders = NULL ;
166
- }
164
+ if (_httpHeaders != NULL ) {
165
+ delete _httpHeaders;
166
+ _httpHeaders = NULL ;
167
167
}
168
168
}
169
169
}
0 commit comments