NBitcoin: NBitcoin doesn't connect to the Bitcoin P2P network only on OSX under 8GB memory

Update. The AddressManager fails on OSX High Sierra under 8GB memory. It doesn’t fail with or over 8GB.

I created a repository that reproduces this issue with a few lines of code in the Program.cs.
Repository: https://github.com/nopara73/NBitcoinBitcoinP2pOsxBug

I also added travis CI integration that shows it runs on Linux, but it doesn’t run on OSX. (It runs on Windows, too.)

Travis builds: https://travis-ci.org/nopara73/NBitcoinBitcoinP2pOsxBug/builds/344928253

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 38 (21 by maintainers)

Most upvoted comments

I can make the tests pass simply changing the NodeConnectionParameters parameters (below my change):

-             var connectionParameters = new NodeConnectionParameters();
+            var connectionParameters = new NodeConnectionParameters()
+            {
+                ReceiveBufferSize = 100 * 5000,
+                SendBufferSize = 100 * 1000
+            };

The article Mac OSX Tuning says that

Starting with OSX 10.5, Apple added “self tuning TCP”, and increased the default maximum socket buffer to 4MB

The article also says that the default new values for Settings for OSX Yosemite/Mavericks/Sierra are:

net.inet.tcp.win_scale_factor: 3 (or 5 in newer versions) net.inet.tcp.autorcvbufmax: 1048576 (or 2097152 in newer versions ) net.inet.tcp.autosndbufmax: 1048576

in NBitcoin, the default values are hardcoded as follow:

ReceiveBufferSize = 1000 * 5000;  
SendBufferSize = 1000 * 1000;

IMO, even when NBitcoin works perfectly well and can be parametrized easily, I think those defaults values should be modify in a way that osx programmers don’t have to deal with this. I’m not sure what the best strategy is (changing the values to fit the known max limits or let the default values or other)

This is not a blocker for us.

inject TraceSourceFactory.CreateTraceSourceFactory with an instance of Func<TraceSource>. (see class NullTraceSource to see an empty implementation)