jklepatch / eattheblocks

Source code for Eat The Blocks, a screencast for Ethereum Dapp Developers
https://eattheblocks.com
4k stars 3.2k forks source link

PancakeSwap Trading Bot: Client network socket disconnected before secure TLS connection was established #64

Closed johndoe75 closed 3 years ago

johndoe75 commented 3 years ago

This issue relates to "348-pancakeswap-trading-bot". I'm running your code 1:1 without any changes except for the WebSocket URL of my Ankr project. Everytime I start, I'm getting this error:

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: Client network socket disconnected before secure TLS connection was established
    at TLSSocket.onConnectEnd (_tls_wrap.js:1095:19)
    at Object.onceWrapper (events.js:286:20)
    at TLSSocket.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
    at ClientRequest.req.on (/root/bsc-sniper-bot/node_modules/ws/lib/websocket.js:555:15)
    at ClientRequest.emit (events.js:198:13)
    at TLSSocket.socketErrorListener (_http_client.js:401:9)
    at TLSSocket.emit (events.js:198:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

I've tried it at my desktop, on a server (other network) and at my work laptop. Always the same result. None of the computers does having a proxy setup or alike.

djammy33 commented 3 years ago

Can you check the following

Press the Windows Key Search For Internet Options Click on "Internet Options" Click On "Connection" Go to LAN Settings Is there a checkmark in "Use Proxy Server for LAN" ? If so, try unchecking it

johndoe75 commented 3 years ago

I've tripple checked my network settings: no proxy setup (MacOS).

Also I've tried to run the code on two different hosted Linux server at different hoster as well – outside my network (Node v10.19.0) to exclude any issues with my network. Same result.

I've also stopped my local firewall (Little Snitch) to exclude this interfering with the WebSocket (never had that before, but well …)

Add: sometimes the error changes:

events.js:353
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20)
Emitted 'error' event on WebSocket instance at:
    at ClientRequest.<anonymous> (/Users/alex/Development/crypto/sniper-bot/node_modules/ws/lib/websocket.js:555:15)
    at ClientRequest.emit (events.js:376:20)
    at TLSSocket.socketErrorListener (_http_client.js:475:9)
    at TLSSocket.emit (events.js:376:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: -54,
  code: 'ECONNRESET',
  syscall: 'read'
}

Upgrading ethers to the latest 5.1.4 did not change anything. Also manually upgrading ws-package to latest 7.4.5 did not help.

johndoe75 commented 3 years ago

First wasn't working this morning, then suddenly it worked. I suspect the issue to be on side of Ankr.