question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connection unexpectedly failed: Unexpected exception while connecting to socket

See original GitHub issue

Since yesterday (apparently at block height 774627), I’m getting the same error as in #170, but with the problem and solution therein definitely not applying to my setup.

I had been running NBXplorer for BTCPayServer for years now, and when this exception first appeared it was on version 2.2.20. So the first thing I tried was upgrading to 2.3.58, and subsequently upgrading bitcoind from 23.0 to 24.0.1. However, the exception persists and it’s unable keep a connection open to bitcoind apparently. The full log looks like this:

info: Configuration:  BTC: Full node version detected: 240001
info: Configuration:  BTC: Node banlist loaded
info: Configuration:  BTC: Loading chain from cache...
info: Configuration:  BTC: Height: 774835
info: Configuration:  BTC: Trying to connect via the P2P protocol to trusted node (127.0.0.1:8333)...
info: Explorer:       BTC: TCP Connection succeed, handshaking...
info: Explorer:       BTC: Handshaked
info: Configuration:  BTC: Loading chain from node
info: Explorer:       BTC: Loading chain...
info: Explorer:       BTC: Chain loaded
info: Explorer:       BTC: NBXplorer is correctly whitelisted by the node
info: Configuration:  BTC: Height: 774836
info: Configuration:  BTC: Saving chain to cache...
info: Configuration:  BTC: Chain cached
info: Explorer:       BTC: Handshaked node
info: Explorer:       BTC: Starting scan at block 774627
info: Events:         BTC: Node state changed: NotStarted => NBXplorerSynching
fail: Explorer:       BTC: Connection unexpectedly failed: Unexpected exception while connecting to socket
info: Events:         BTC: Node state changed: NBXplorerSynching => NotStarted
info: Configuration:  BTC: Testing RPC connection to http://127.0.0.1:8332/
fail: Explorer:       BTC: Unhandled error in IndexBlockLoop
fail: Explorer:       System.OperationCanceledException: The peer has been disconnected
         at NBXplorer.BlockDownloader.DownloadBlocks(BlockLocator fork, CancellationToken cancellationToken)+MoveNext() in /opt/nbxplorer/NBXplorer/BlockDownloader.cs:line 57
         at NBXplorer.BlockDownloader.DownloadBlocks(BlockLocator fork, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
         at NBXplorer.ExplorerBehavior.IndexBlockLoop(Node node, CancellationToken cancellationToken) in /opt/nbxplorer/NBXplorer/ExplorerBehavior.cs:line 319
         at NBXplorer.ExplorerBehavior.IndexBlockLoop(Node node, CancellationToken cancellationToken) in /opt/nbxplorer/NBXplorer/ExplorerBehavior.cs:line 319
info: Configuration:  BTC: RPC connection successful
info: Configuration:  BTC: Full node version detected: 240001
info: Configuration:  BTC: Loading chain from cache...

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Reactions:5
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
raucaocommented, Feb 8, 2023

2.3.60 didn’t fix it for me. But migrating to Postgres worked.

Thanks. 🙏

1reaction
NicolasDoriercommented, Feb 7, 2023

Also you can try v2.3.60 that I just pushed, that may solve your issue on the old backend. But once again, I advise you to use a postgres backend.

To migrate, use env variables: (you can keep them after migrating without issue)

      NBXPLORER_POSTGRES: User ID=postgres;Host=postgres;Port=5432;Application Name=nbxplorer;MaxPoolSize=20;Database=nbxplorer
      NBXPLORER_AUTOMIGRATE: 1
      NBXPLORER_NOMIGRATEEVTS: 1

If you run btcpay with you get more feature using the new backend:

BTCPAY_EXPLORERPOSTGRES: User ID=postgres;Host=postgres;Port=5432;Application Name=btcpayserver;MaxPoolSize=80;Database=nbxplorer
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected exception while connecting to socket · Issue ...
Describe the problem/bug. Connection unexpectedly failed: Unexpected exception while connecting to socket in NBXplorer logs
Read more >
Why do my TCP clients fail to connect to my server with a ...
"No connection could be made because the target machine actively refused it" - the server can hold only so many clients in its...
Read more >
Troubleshooting connection issues
IO client will always try to reconnect, unless specifically told otherwise. Let's review how you can troubleshoot a connection failure.
Read more >
PostgreSQL Error: server closed the connection ...
I get the same error when I try connecting from psql . I have got this error 2 days ago but after restarting...
Read more >
DataDirect What does a "socket closed" error mean with an ...
A "socket closed" error means that the connection has been terminated, however, no specific reason was provided/returned.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found