I noticed that wget still hangs if the https server dies after the
initial handshake completes.
I found out it is due to the second call to SSL_shutdown locking up.
Well, it seems dumb to politely send a "close notify" alert to a server
that is dead, I think it makes more sense to just go away after the
server has already timed out.
So, here is my solution:
In http.c, define a new macro SHUTDOWN_SSL2
#ifdef HAVE_SSL
# define SHUTDOWN_SSL(ssl) do { \
if (ssl) \
shutdown_ssl (ssl); \
} while (0)
# define SHUTDOWN_SSL2(ssl) do { \
if (ssl) \
shutdown_ssl_when_connection_is_dead (ssl); \
} while (0)
#else
# define SHUTDOWN_SSL(ssl)
# define SHUTDOWN_SSL2(ssl)
#endif
and change the CLOSE_INVALIDATE macro to call the new SHUTDOWN_SSL2
#define CLOSE_INVALIDATE(fd) do { \
SHUTDOWN_SSL2 (ssl); \
CLOSE (fd); \
if (pc_active_p && (fd) == pc_last_fd) \
invalidate_persistent (); \
} while (0)
And in gen_sslfunc.c define a new routine
"shutdown_ssl_when_connection_is_dead"
void
shutdown_ssl_when_connection_is_dead (SSL* con)
{
if (con == NULL)
return;
SSL_shutdown (con);
SSL_free (con);
}
I tested the fix with this command:
wget --read-timeout=5 --tries=1 -O boz
https://some_malfunctioning_server.com
It times out after 5 seconds, as it should.
What do you think?