OpenSSL::SSL::SSLError SSL_accept returned=1 errno=0 state=unknown state: tlsv1 alert protocol version
That is a common OpenSSL response when the TCP stream below the handshake is broken. You say you are pentesting at the moment this happens, this has network security connotations but not the ones one would probably guess at first. This answer is an educated guess based on seeing that error several times.
When your session is asleep it does not send keepalive packets (i.e. does not send extra ACKs). Such a "dead" TCP session will be cut off by a stateful firewall, no matter if the firewall considers the connection valid (or harmless) or not. Since you are pentesting I would imagine you are working within a network where several firewalls are in place.
Why would a stateful firewall do this?
Today, stateless firewalls are pretty much history* therefore all firewalls are stateful, they keep the state (and history) for each connection that goes through the firewall. They perform this not only for NATs but for any traffic passing through the firewall. Such a stateful firewall is vulnerable to a DoS attack by leaving too many hanging connections and filling its memory. To prevent that a stateful firewall have a timeout upon which it drops the hanging (no traffic during the timeout) connection.
When you wake up your SSL session, it sends an ACK. But the firewall had long dropped that connection from its memory and is clueless about the existence of the TCP session, therefore it answers with RST. The RST provokes a state=unknown
error from the SSL level.
The system at the other side of the firewall may well be aware of your connection, and would answer had the ACK reached it. But the firewall will not let that pass.
What can you do about it?
Not much. You could run a stateful proxy on your own machine which would keep sending TCP keepalive on one side (the outside), but would not require keepalives on the other side (the inside, loopback).
Yet if you, for example, put your entire machine to sleep, then the stateful proxy will not send extra ACKs anyway defeating it purpose (and it will make connection debugging even harder that it already is with just the firewalls).
* A stateless firewall is vulnerable to trivial attacks (bypasses), such as IP fragmentation of the initial SYN packet.