This commit fixes some situations which could appear in TLS code when dealing with shutdown messages and lead to crashes.