Search code examples
node.jswebserverhyperledger-fabric

node and tcp connections


I'm throubleshooting a scenario with a node sever where there are too many ESTABLISHED connections, even when there are no active requests. This from a test environment but same behavior is found on PROD.

This is the number of Established connections on each IP of the test machine:

572 127.0.0.1
 48 172.18.0.23
 48 172.18.0.16
 47 172.18.0.18
 47 172.18.0.15
 46 172.18.0.24
 46 172.18.0.20
 31 0.0.0.0
 26 
  2 172.31.45.51

On localhost, Established connections look like this:

tcp        0      0 localhost:59596         localhost:8051          ESTABLISHED hyperledger 478386467  3632665/node /opt/h 
tcp        0      0 localhost:44164         localhost:2379          ESTABLISHED etcd       459192509  529/etcd            
tcp        0      0 localhost:9050          localhost:48376         ESTABLISHED root       478391433  1653221/docker-prox 
tcp        0      0 localhost:8050          localhost:55040         ESTABLISHED root       478390603  1652718/docker-prox 
tcp        0      0 localhost:39050         localhost:8050          ESTABLISHED hyperledger 478550015  3632665/node /opt/h 
tcp        0      0 localhost:8051          localhost:60804         ESTABLISHED root       478579826  1652946/docker-prox 
tcp        0      0 localhost:7051          localhost:44068         ESTABLISHED root       478581029  3355251/docker-prox 
tcp        0      0 localhost:37922         localhost:9050          ESTABLISHED hyperledger 478382004  3632665/node /opt/h 
tcp        0      0 localhost:53382         localhost:8050          ESTABLISHED hyperledger 478537715  3632665/node /opt/h 
tcp        0      0 localhost:45914         localhost:7050          ESTABLISHED hyperledger 478384838  3632665/node /opt/h 
tcp        0      0 localhost:9051          localhost:36842         ESTABLISHED root       478388152  1653426/docker-prox 
tcp        0      0 localhost:56526         localhost:7050          ESTABLISHED hyperledger 478390799  3632665/node /opt/h 
tcp        0      0 localhost:53918         localhost:7051          ESTABLISHED hyperledger 478608229  3632665/node /opt/h 
tcp        0      0 localhost:8051          localhost:42296         ESTABLISHED root       478537891  1652946/docker-prox 
tcp        0      0 localhost:7050          localhost:56334         ESTABLISHED root       478390037  1652249/docker-prox 

...

The localhost connections are half initiated by user root, and the other half by hyperledger user, this is an example with 1 set:

tcp        0      0 localhost:7051          localhost:53946         ESTABLISHED root       478608259  3355251/docker-prox 
tcp        0      0 localhost:53946         localhost:7051          ESTABLISHED hyperledger 478609232  3632665/node /opt/h 

localhost:53946 -> localhost:7051, this is the node server connecting to a fabric node, and localhost:7051 -> localhost:53946, would be the fabric node running on a container connecting back to node.

As I was saying, this happens even when there are no calls even made. Does this mean that the node server isn't closing the connections? I also don't understand why there are so many node connections running on different Ports. Node webserver is set to lisetn on port 5000, but then uses the fabric SDK to connect to a fabric node on docker. These are the connections and looks like are not closing, even though there is a "gateway.disconnect()" call that should close it.

There are only two node processes:

1716966 ?        Sl    17:15 node app/main.js name - hyperledger-explorer
3632665 ?        Ssl    7:11 node /opt/hyperledger/vm1/fabric/server/server.js

I think I'm missing some core concepts here, I can't figure out what's wrongs. I'm thinking something with the node app, but couldn't find anything so far and I don't quite get the netstat info.


Solution

  • This seems to be a known issue of the now legacy node SDK fabric-network. For fabric 2.4v onwards, the new fabric-gateway sdk is recommended for improved management of resources.