2

I'm using Windows Server 2012 as a workstation. The problem is that HTTPS connection initiated by node.js randomly fails. Probably this is system-wide issue and not only node is affected, but it appears mostly with node.

Because any HTTPS request can randomly fail, npm install is a lottery and for bigger packages it will always fail with ECONNRESET at TLSWrap.onread error after endless retries. Another example is my node script to fetch folder content from Github, if almost always fails trying do download first file, but sometime it can fetch a few and then fail.

Only standard Windows Firewall and System Center Endpoint Protection (AKA Microsoft Security Essentials) is installed on that machine and I tried to switch them both off - no help. Also changing network card, IP address, gateway or even ISP didn't help either. I also tried uninstall and then install again some SSL-related windows updates and it also didn't help. However everything works fine on the another PC connected to the same switch and even on this PC in Linux. The time and date is correct, browsing (HTTP and HTTPS) is also fine except rare Connection Reset errors on some, but not all HTTPS-enabled sites (for example imgur.com).

Here is two outputs from openssl, made a few seconds apart, first one passes, second fails.

openssl s_client -msg -debug -state -connect www.npmjs.com:443

First one is too big to put into the post, so here is pastebin link.

Second one:

CONNECTED(00000138)
write to 0xf4e608 [0xf87210] (307 bytes => 307 (0x133))
0000 - 16 03 01 01 2e 01 00 01-2a 03 03 4b 71 63 8e 02   ........*..Kqc..
0010 - 73 68 40 9b 77 eb 06 5f-47 58 c5 3e d5 0f 33 1d   sh@.w.._GX.>..3.
0020 - 76 73 d1 b0 0a 11 b8 84-29 32 e3 00 00 ac c0 30   vs......)2.....0
0030 - c0 2c c0 28 c0 24 c0 14-c0 0a 00 a5 00 a3 00 a1   .,.(.$..........
0040 - 00 9f 00 6b 00 6a 00 69-00 68 00 39 00 38 00 37   ...k.j.i.h.9.8.7
0050 - 00 36 00 88 00 87 00 86-00 85 c0 32 c0 2e c0 2a   .6.........2...*
0060 - c0 26 c0 0f c0 05 00 9d-00 3d 00 35 00 84 c0 2f   .&.......=.5.../
0070 - c0 2b c0 27 c0 23 c0 13-c0 09 00 a4 00 a2 00 a0   .+.'.#..........
0080 - 00 9e 00 67 00 40 00 3f-00 3e 00 33 00 32 00 31   ...g.@.?.>.3.2.1
0090 - 00 30 00 9a 00 99 00 98-00 97 00 45 00 44 00 43   .0.........E.D.C
00a0 - 00 42 c0 31 c0 2d c0 29-c0 25 c0 0e c0 04 00 9c   .B.1.-.).%......
00b0 - 00 3c 00 2f 00 96 00 41-00 07 c0 11 c0 07 c0 0c   .<./...A........
00c0 - c0 02 00 05 00 04 c0 12-c0 08 00 16 00 13 00 10   ................
00d0 - 00 0d c0 0d c0 03 00 0a-00 ff 01 00 00 55 00 0b   .............U..
00e0 - 00 04 03 00 01 02 00 0a-00 1c 00 1a 00 17 00 19   ................
00f0 - 00 1c 00 1b 00 18 00 1a-00 16 00 0e 00 0d 00 0b   ................
0100 - 00 0c 00 09 00 0a 00 23-00 00 00 0d 00 20 00 1e   .......#..... ..
0110 - 06 01 06 02 06 03 05 01-05 02 05 03 04 01 04 02   ................
0120 - 04 03 03 01 03 02 03 03-02 01 02 02 02 03 00 0f   ................
0130 - 00 01 01                                          ...
>>> TLS 1.2  [length 0005]
    16 03 01 01 2e
>>> TLS 1.2 Handshake [length 012e], ClientHello
    01 00 01 2a 03 03 4b 71 63 8e 02 73 68 40 9b 77
    eb 06 5f 47 58 c5 3e d5 0f 33 1d 76 73 d1 b0 0a
    11 b8 84 29 32 e3 00 00 ac c0 30 c0 2c c0 28 c0
    24 c0 14 c0 0a 00 a5 00 a3 00 a1 00 9f 00 6b 00
    6a 00 69 00 68 00 39 00 38 00 37 00 36 00 88 00
    87 00 86 00 85 c0 32 c0 2e c0 2a c0 26 c0 0f c0
    05 00 9d 00 3d 00 35 00 84 c0 2f c0 2b c0 27 c0
    23 c0 13 c0 09 00 a4 00 a2 00 a0 00 9e 00 67 00
    40 00 3f 00 3e 00 33 00 32 00 31 00 30 00 9a 00
    99 00 98 00 97 00 45 00 44 00 43 00 42 c0 31 c0
    2d c0 29 c0 25 c0 0e c0 04 00 9c 00 3c 00 2f 00
    96 00 41 00 07 c0 11 c0 07 c0 0c c0 02 00 05 00
    04 c0 12 c0 08 00 16 00 13 00 10 00 0d c0 0d c0
    03 00 0a 00 ff 01 00 00 55 00 0b 00 04 03 00 01
    02 00 0a 00 1c 00 1a 00 17 00 19 00 1c 00 1b 00
    18 00 1a 00 16 00 0e 00 0d 00 0b 00 0c 00 09 00
    0a 00 23 00 00 00 0d 00 20 00 1e 06 01 06 02 06
    03 05 01 05 02 05 03 04 01 04 02 04 03 03 01 03
    02 03 03 02 01 02 02 02 03 00 0f 00 01 01
read from 0xf4e608 [0xf8c770] (7 bytes => -1 (0xFFFFFFFF))
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 307 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : 0000
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1457623360
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---
SSL_connect:before/connect initialization
SSL_connect:SSLv2/v3 write client hello A
SSL_connect:error in SSLv2/v3 read server hello A
write:errno=10054

Here is response from www.howsmyssl.com API requested from node.js

{  
   "given_cipher_suites":[  
      "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
      "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
      "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
      "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
      "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256",
      "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
      "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
      "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
      "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256",
      "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
      "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
      "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
      "TLS_DH_DSS_WITH_AES_256_GCM_SHA384",
      "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384",
      "TLS_DH_RSA_WITH_AES_256_GCM_SHA384",
      "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384",
      "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256",
      "TLS_DH_RSA_WITH_AES_256_CBC_SHA256",
      "TLS_DH_DSS_WITH_AES_256_CBC_SHA256",
      "TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
      "TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
      "TLS_DH_RSA_WITH_AES_256_CBC_SHA",
      "TLS_DH_DSS_WITH_AES_256_CBC_SHA",
      "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384",
      "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384",
      "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384",
      "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384",
      "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA",
      "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA",
      "TLS_RSA_WITH_AES_256_GCM_SHA384",
      "TLS_RSA_WITH_AES_256_CBC_SHA256",
      "TLS_RSA_WITH_AES_256_CBC_SHA",
      "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
      "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
      "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
      "TLS_DH_DSS_WITH_AES_128_GCM_SHA256",
      "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256",
      "TLS_DH_RSA_WITH_AES_128_GCM_SHA256",
      "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256",
      "TLS_DH_RSA_WITH_AES_128_CBC_SHA256",
      "TLS_DH_DSS_WITH_AES_128_CBC_SHA256",
      "TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
      "TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
      "TLS_DH_RSA_WITH_AES_128_CBC_SHA",
      "TLS_DH_DSS_WITH_AES_128_CBC_SHA",
      "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256",
      "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256",
      "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256",
      "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256",
      "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
      "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
      "TLS_RSA_WITH_AES_128_GCM_SHA256",
      "TLS_RSA_WITH_AES_128_CBC_SHA256",
      "TLS_RSA_WITH_AES_128_CBC_SHA",
      "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
      "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
      "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
      "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
      "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA",
      "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA",
      "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA",
      "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
      "TLS_RSA_WITH_3DES_EDE_CBC_SHA",
      "TLS_EMPTY_RENEGOTIATION_INFO_SCSV"
   ],
   "ephemeral_keys_supported":true,
   "session_ticket_supported":true,
   "tls_compression_supported":false,
   "unknown_cipher_suite_supported":false,
   "beast_vuln":false,
   "able_to_detect_n_minus_one_splitting":false,
   "insecure_cipher_suites":{  

   },
   "tls_version":"TLS 1.2",
   "rating":"Probably Okay"
}

I already spent endless hours trying to resolve this issue, but nothing works. I'm unable to use node on this PC and in the modern world it hurts, so I'm posting it here as a last hope to avoid reinstall OS and all software.

0

You could reset the TCP/IP stack by running these commands in Command Prompt as administrator :

  • Reset WINSOCK entries to installation defaults: netsh winsock reset catalog
  • Reset IPv4 TCP/IP stack to installation defaults. netsh int ipv4 reset reset.log
  • Reset IPv6 TCP/IP stack to installation defaults. netsh int ipv6 reset reset.log
  • Reset the winsock catalog : netsh winsock reset catalog
  • Or just : netsh int ip reset reset.log
  • And netsh winsock reset catalog

There might be some duplication in the above commands, but this are all the reset commands that I know of.

If everything fails, it wouldn't hurt to disable IPv6 and even sfc /scannow to verify Windows components.

  • Well, I don't think this is a node bug, because the same version of node works fine on another PC. And I just tested with Python script and also got Connection reset error. Also I have no control over web servers affected by this error (for example npmjs.com or raw.githubusercontent.com). I think this is system-wide issue caused by Windows update or other software. Thank you for help anyway. – graycrow Mar 15 '16 at 22:05
  • You are probably right. If this only happens on one computer, I have listed above all the reset commands I know for Windows. Is the other computer also on Windows Server 2012? – harrymc Mar 16 '16 at 8:35
  • IPv6 is disabled, those commands I tried before and it didn't helped. sfc /scannow found nothing suspicious. The other PC is on Windows Server 2008 R2. It's slightly different OS, I know, but it's just to prove that issue is not caused by network hardware or ISP. And it's almost impossible that node.js and Python both have bugs only related to Server 2012. – graycrow Mar 17 '16 at 8:49
  • Has this worked in any other Windows Server 2012 installation? You might be encountering some incompatibility. As in the previous version of my answer, this might be with Keep-alive or idle sockets. I will later have a look at their parameters in WS2012, although not sure that you can control the client ones. You might also consider trying WS2012 R2, even inside a VM as a trial version. – harrymc Mar 17 '16 at 10:32
  • Also, Keep-alive and idle sockets suggest the possibility that the reason for these random errors is a timeout because the other side is overloaded, so the connection just times out. Try to see if the problem is equally frequent on different periods such as early morning or late night. – harrymc Mar 18 '16 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.