ratchet detected an invalid reserve code - immediate disconnect after connection under SSL

Hi.
I'm testing ratchet (updated) under apache with SSL (Let's Encrypt)
> Server version: Apache/2.4.6 (CentOS)
> Server built:   Apr 20 2018 18:10:38
> /usr/bin/supervisord -v 3.1.4
>   - Updating ratchet/rfc6455 (v0.2.3 => 0.2.4): Downloading (100%)
>   - Updating react/event-loop (v0.4.3 => v0.5.2): Downloading (100%)
>   - Updating react/promise-timer (v1.2.1 => v1.3.0): Downloading (100%)
>   - Updating react/socket (v0.8.10 => v0.8.11): Downloading (100%)
>   - Updating symfony/polyfill-mbstring (v1.7.0 => v1.8.0): Downloading (100%)
>   - Updating symfony/http-foundation (v4.0.6 => v4.0.9): Downloading (100%)
>   - Updating symfony/routing (v4.0.6 => v4.0.9): Downloading (100%)
> 


And I`m encountering a random problem during connection, sometimes everything works just fine, but other times when I'm connecting, after sending default websocket HTTP connection header I receive from Ratchet this error:

> [2 characters from default websocket msg frame]ratchet detected an invalid reserve code

Note that in this case I didn't received the normal response after sending the HTTP connection header.
Here is a normal operation example:
```

TIdSSLIOHandlerSocketOpenSSL#hsResolving:Resolving XXXXXXXXXXXXXXXX.
TIdSSLIOHandlerSocketOpenSSL#hsConnecting:Connecting to XXX.XXX.XXX.XXX.
StatusInfo:SSL status: "before/connect initialization"
StatusInfo:SSL status: "before/connect initialization"
StatusInfo:SSL status: "SSLv2/v3 write client hello A"
StatusInfo:SSL status: "SSLv3 read server hello A"
StatusInfo:SSL status: "SSLv3 read server certificate A"
StatusInfo:SSL status: "SSLv3 read server key exchange A"
StatusInfo:SSL status: "SSLv3 read server done A"
StatusInfo:SSL status: "SSLv3 write client key exchange A"
StatusInfo:SSL status: "SSLv3 write change cipher spec A"
StatusInfo:SSL status: "SSLv3 write finished A"
StatusInfo:SSL status: "SSLv3 flush data"
StatusInfo:SSL status: "SSLv3 read server session ticket A"
StatusInfo:SSL status: "SSLv3 read finished A"
StatusInfo:SSL status: "SSL negotiation finished successfully"
StatusInfo:SSL status: "SSL negotiation finished successfully"
StatusInfo:Cipher: name = ECDHE-RSA-AES128-GCM-SHA256; description = ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH     Au=RSA  Enc=AESGCM(128) Mac=AEAD
; bits = 128; version = TLSv1/SSLv3; 
TIdTCPClient#hsConnected:Connected.
SENDING
GET /wss/ HTTP/1.1
Host: XXXXXXXXXXXXXX:XXXX
User-Agent: Delphi TCP
Connection: keep-alive, Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: wljiVCqHsNeAbmqn4741Pw==

RECEIVING
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: Ad3sUpmwS8qGAbIshGLzWnT4+j0=
X-Powered-By: Ratchet/0.4.1

.... normal operation

```
Apache log:
```
[Thu May 10 14:00:59.348194 2018] [ssl:debug] [pid 21725] ssl_engine_kernel.c(225): [client 192.168.1.1:50603] AH02034: Initial (No.1) HTTPS request received for child 4 (server XXXXXXXXXXXXXXXXXX:443)
[Thu May 10 14:00:59.348302 2018] [authz_core:debug] [pid 21725] mod_authz_core.c(835): [client 192.168.1.1:50603] AH01628: authorization result: granted (no directives)
[Thu May 10 14:00:59.348368 2018] [proxy:debug] [pid 21725] mod_proxy.c(1123): [client 192.168.1.1:50603] AH01143: Running scheme ws handler (attempt 0)
[Thu May 10 14:00:59.348384 2018] [proxy_ajp:debug] [pid 21725] mod_proxy_ajp.c(722): [client 192.168.1.1:50603] AH00894: declining URL ws://localhost:8080//
[Thu May 10 14:00:59.348397 2018] [proxy_fcgi:debug] [pid 21725] mod_proxy_fcgi.c(972): [client 192.168.1.1:50603] AH01076: url: ws://localhost:8080// proxyname: (null) proxyport: 0
[Thu May 10 14:00:59.348408 2018] [proxy_fcgi:debug] [pid 21725] mod_proxy_fcgi.c(975): [client 192.168.1.1:50603] AH01077: declining URL ws://localhost:8080//
[Thu May 10 14:00:59.348421 2018] [proxy_http:debug] [pid 21725] mod_proxy_http.c(1930): [client 192.168.1.1:50603] AH01113: HTTP: declining URL ws://localhost:8080//
[Thu May 10 14:00:59.348432 2018] [proxy_scgi:debug] [pid 21725] mod_proxy_scgi.c(517): [client 192.168.1.1:50603] AH00865: declining URL ws://localhost:8080//
[Thu May 10 14:00:59.348443 2018] [proxy_wstunnel:debug] [pid 21725] mod_proxy_wstunnel.c(336): [client 192.168.1.1:50603] AH02451: serving URL ws://localhost:8080//
[Thu May 10 14:00:59.348454 2018] [proxy:debug] [pid 21725] proxy_util.c(2203): AH00942: WS: has acquired connection for (localhost)
[Thu May 10 14:00:59.348467 2018] [proxy:debug] [pid 21725] proxy_util.c(2256): [client 192.168.1.1:50603] AH00944: connecting ws://localhost:8080// to localhost:8080
[Thu May 10 14:00:59.348481 2018] [proxy:debug] [pid 21725] proxy_util.c(2422): [client 192.168.1.1:50603] AH00947: connected // to localhost:8080
[Thu May 10 14:00:59.348563 2018] [proxy:debug] [pid 21725] proxy_util.c(2658): AH00951: WS: backend socket is disconnected.
[Thu May 10 14:00:59.348652 2018] [proxy:debug] [pid 21725] proxy_util.c(2789): (111)Connection refused: AH00957: WS: attempt to connect to [::1]:8080 (localhost) failed
[Thu May 10 14:00:59.348748 2018] [proxy:debug] [pid 21725] proxy_util.c(2798): AH02824: WS: connection established with 127.0.0.1:8080 (localhost)
[Thu May 10 14:00:59.348807 2018] [proxy:debug] [pid 21725] proxy_util.c(2938): AH00962: WS: connection complete to [::1]:8080 (localhost)
[Thu May 10 14:00:59.349640 2018] [proxy_wstunnel:debug] [pid 21725] mod_proxy_wstunnel.c(257): [client 192.168.1.1:50603] AH02445: woke from poll(), i=1
[Thu May 10 14:00:59.349661 2018] [proxy_wstunnel:debug] [pid 21725] mod_proxy_wstunnel.c(266): [client 192.168.1.1:50603] AH02446: sock was readable
success^

```

Now an example with error:


```

TIdSSLIOHandlerSocketOpenSSL#hsResolving:Resolving XXXXXXXXXXXXXXXX.
TIdSSLIOHandlerSocketOpenSSL#hsConnecting:Connecting to XXX.XXX.XXX.XXX.
StatusInfo:SSL status: "before/connect initialization"
StatusInfo:SSL status: "before/connect initialization"
StatusInfo:SSL status: "SSLv2/v3 write client hello A"
StatusInfo:SSL status: "SSLv3 read server hello A"
StatusInfo:SSL status: "SSLv3 read server certificate A"
StatusInfo:SSL status: "SSLv3 read server key exchange A"
StatusInfo:SSL status: "SSLv3 read server done A"
StatusInfo:SSL status: "SSLv3 write client key exchange A"
StatusInfo:SSL status: "SSLv3 write change cipher spec A"
StatusInfo:SSL status: "SSLv3 write finished A"
StatusInfo:SSL status: "SSLv3 flush data"
StatusInfo:SSL status: "SSLv3 read server session ticket A"
StatusInfo:SSL status: "SSLv3 read finished A"
StatusInfo:SSL status: "SSL negotiation finished successfully"
StatusInfo:SSL status: "SSL negotiation finished successfully"
StatusInfo:Cipher: name = ECDHE-RSA-AES128-GCM-SHA256; description = ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH     Au=RSA  Enc=AESGCM(128) Mac=AEAD
; bits = 128; version = TLSv1/SSLv3; 
TIdTCPClient#hsConnected:Connected.
SENDING
GET /wss/ HTTP/1.1
Host: XXXXXXXXXXXXXX:XXXX
User-Agent: Delphi TCP
Connection: keep-alive, Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: wljiVCqHsNeAbmqn4741Pw==

RECEIVING
__ratchet detected an invalid reserve code

```
Apache log:
```
[Thu May 10 14:00:07.752369 2018] [ssl:debug] [pid 21722] ssl_engine_kernel.c(225): [client 192.168.1.1:50601] AH02034: Initial (No.1) HTTPS request received for child 1 (server XXXXXXXXXXXXXXXXXX:443)
[Thu May 10 14:00:07.752480 2018] [authz_core:debug] [pid 21722] mod_authz_core.c(835): [client 192.168.1.1:50601] AH01628: authorization result: granted (no directives)
[Thu May 10 14:00:07.752532 2018] [proxy:debug] [pid 21722] mod_proxy.c(1123): [client 192.168.1.1:50601] AH01143: Running scheme ws handler (attempt 0)
[Thu May 10 14:00:07.752548 2018] [proxy_ajp:debug] [pid 21722] mod_proxy_ajp.c(722): [client 192.168.1.1:50601] AH00894: declining URL ws://localhost:8080//
[Thu May 10 14:00:07.752560 2018] [proxy_fcgi:debug] [pid 21722] mod_proxy_fcgi.c(972): [client 192.168.1.1:50601] AH01076: url: ws://localhost:8080// proxyname: (null) proxyport: 0
[Thu May 10 14:00:07.752573 2018] [proxy_fcgi:debug] [pid 21722] mod_proxy_fcgi.c(975): [client 192.168.1.1:50601] AH01077: declining URL ws://localhost:8080//
[Thu May 10 14:00:07.752586 2018] [proxy_http:debug] [pid 21722] mod_proxy_http.c(1930): [client 192.168.1.1:50601] AH01113: HTTP: declining URL ws://localhost:8080//
[Thu May 10 14:00:07.752599 2018] [proxy_scgi:debug] [pid 21722] mod_proxy_scgi.c(517): [client 192.168.1.1:50601] AH00865: declining URL ws://localhost:8080//
[Thu May 10 14:00:07.752610 2018] [proxy_wstunnel:debug] [pid 21722] mod_proxy_wstunnel.c(336): [client 192.168.1.1:50601] AH02451: serving URL ws://localhost:8080//
[Thu May 10 14:00:07.752622 2018] [proxy:debug] [pid 21722] proxy_util.c(2203): AH00942: WS: has acquired connection for (localhost)
[Thu May 10 14:00:07.752636 2018] [proxy:debug] [pid 21722] proxy_util.c(2256): [client 192.168.1.1:50601] AH00944: connecting ws://localhost:8080// to localhost:8080
[Thu May 10 14:00:07.752650 2018] [proxy:debug] [pid 21722] proxy_util.c(2422): [client 192.168.1.1:50601] AH00947: connected // to localhost:8080
[Thu May 10 14:00:07.753080 2018] [proxy_wstunnel:debug] [pid 21722] mod_proxy_wstunnel.c(257): [client 192.168.1.1:50601] AH02445: woke from poll(), i=1
[Thu May 10 14:00:07.753102 2018] [proxy_wstunnel:debug] [pid 21722] mod_proxy_wstunnel.c(266): [client 192.168.1.1:50601] AH02446: sock was readable
[Thu May 10 14:00:07.753170 2018] [proxy:debug] [pid 21722] proxy_util.c(2218): AH00943: WS: has released connection for (localhost)
[Thu May 10 14:00:07.753238 2018] [ssl:debug] [pid 21722] ssl_engine_io.c(993): [client 192.168.1.1:50601] AH02001: Connection closed to child 1 with standard shutdown (server XXXXXXXXXXXXXXXXXX:443)
^fail
```

My apache config.:
```
<IfModule mod_ssl.c>
<VirtualHost  *:8443>
    ProxyPreserveHost On
    ProxyPass "/ws" "ws://localhost:8080/"
    ProxyPass "/wss" "ws://localhost:8080/"
    ProxyPassReverse "/ws" "ws://localhost:8080/"
    ProxyPassReverse "/wss" "ws://localhost:8080/"

    ServerName XXXXXXXXXXXXXXXXXXX
    Alias /index.php /usr/share/httpd/noindex/index.html

SSLCertificateFile /etc/letsencrypt/live/XXXXXXX/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/XXXXXXX/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/XXXXXXX/chain.pem
</VirtualHost>
</IfModule>

```


Has someone experienced this problem before?
*Connecting directly without SSL always worked.

Thanks!