Hyperledger-fabric-node Error: 14 UNAVAILABLE: failed to connect to all addresses

1.3k views Asked by At

I'm trying to build a front-end for my fabirc network by fabric-sdk-node, but got some err. Here is my err message.

root@oyu-virtual-machine:~/hyperledger-fabric/test/webapp# node get.js
Load privateKey and signedCert
Get History
Assigning transaction_id:  467c10baa2720435fc664ebecc8e2e8dc2dc833277c1494ffd0b9cf6dbeb99cf
returned from gethistory
Gethistory result count =  1
error from gethistory =  Error: 14 UNAVAILABLE: failed to connect to all addresses
at Object.exports.createStatusError (/root/hyperledger-fabric/test/webapp/node_modules/fabric-client/node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (/root/hyperledger-fabric/test/webapp/node_modules/fabric-client/node_modules/grpc/src/client_interceptors.js:1209:28)
at InterceptingListener._callNext (/root/hyperledger-fabric/test/webapp/node_modules/fabric-client/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/root/hyperledger-fabric/test/webapp/node_modules/fabric-client/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/root/hyperledger-fabric/test/webapp/node_modules/fabric-client/node_modules/grpc/src/client_interceptors.js:847:24) {
  code: 14,
  metadata: Metadata { _internal_repr: {}, flags: 0 },
  details: 'failed to connect to all addresses'
}
Response is  Error: 14 UNAVAILABLE: failed to connect to all addresses

And here is my js code, which try to send request to invoke chaincode message. I copy it from the fabric-samples with only a little bit modification.

'use strict';

var hfc = require('fabric-client'); 
var path = require('path'); 
var util = require('util'); 
var sdkUtils = require('fabric-client/lib/utils') 
const fs = require('fs'); 
var options = { 
    user_id: '[email protected]', 
    msp_id:'OrgSellMSP', 
    channel_id: 'mychannel', 
    chaincode_id: 'sellcc', 
    peer_url: 'grpcs://192.168.1.2:7051',
    privateKeyFolder:'/root/hyperledger-fabric/test/basic-network/crypto-config/peerOrganizations/sell.trace.com/users/[email protected]/msp/keystore', 
    signedCert:'/root/hyperledger-fabric/test/basic-network/crypto-config/peerOrganizations/sell.trace.com/users/[email protected]/msp/signcerts/[email protected]', 
    peer_tls_cacerts:'/root/hyperledger-fabric/test/basic-network/crypto-config/peerOrganizations/sell.trace.com/peers/peer0.sell.trace.com/tls/ca.crt', 
    server_hostname: "peer0.sell.trace.com" 
};

var channel = {}; 
var client = null; 
var targets = []; 
var tx_id = null; 
const getKeyFilesInDir = (dir) => { 
        const files = fs.readdirSync(dir) 
        const keyFiles = [] 
        files.forEach((file_name) => { 
                let filePath = path.join(dir, file_name) 
                if (file_name.endsWith('_sk')) { 
                        keyFiles.push(filePath) 
                } 
        }) 
        return keyFiles 
} 
Promise.resolve().then(() => { 
    console.log("Load privateKey and signedCert"); 
    client = new hfc(); 
    var    createUserOpt = { 
                username: options.user_id, 
                mspid: options.msp_id, 
                cryptoContent: { privateKey: getKeyFilesInDir(options.privateKeyFolder)[0], 
  signedCert: options.signedCert } 
         } 
return sdkUtils.newKeyValueStore({ 
                        path: "/tmp/fabric-client-stateStore/" 
                }).then((store) => { 
                        client.setStateStore(store) 
                         return client.createUser(createUserOpt) 
                 }) 
}).then((user) => { 
    channel = client.newChannel(options.channel_id); 
    
    let data = fs.readFileSync(options.peer_tls_cacerts); 
    let peer = client.newPeer(options.peer_url, 
         { 
            pem: Buffer.from(data).toString(), 
             'ssl-target-name-override': options.server_hostname 
        } 
    ); 
    peer.setName("peer0"); 
    channel.addPeer(peer); 
    return; 
}).then(() => { 
    console.log("Get History"); 
    var transaction_id = client.newTransactionID(); 
    console.log("Assigning transaction_id: ", transaction_id._transaction_id); 
    const request = { 
        chaincodeId: options.chaincode_id, 
        txId: transaction_id, 
        fcn: 'githistory', 
        args: 's-001'
    }; 
     return channel.queryByChaincode(request); 
}).then((query_responses) => { 
    console.log("returned from gethistory"); 
    if (!query_responses.length) { 
        console.log("No payloads were returned from gethistory"); 
    } else { 
        console.log("Gethistory result count = ", query_responses.length) 
    } 
    if (query_responses[0] instanceof Error) { 
        console.error("error from gethistory = ", query_responses[0]); 
    } 
    console.log("Response is ", query_responses[0].toString()); 
}).catch((err) => { 
    console.error("Caught Error", err); 
});

I'm a very newbie in nodejs, and I didn't learn nodejs before. Thanks in advance.


NEW EDIT

Here is my err message in peer0.sell.trace.com, which is the anchor of the organization.

2021-04-27 06:24:12.960 UTC [ConnProducer] NewConnection -> ERRO 035 Failed connecting to orderer.trace.com:7050 , error: context deadline exceeded
2021-04-27 06:24:12.960 UTC [deliveryClient] connect -> ERRO 036 Failed obtaining connection: Could not connect to any of the endpoints: [orderer.trace.com:7050]
2021-04-27 06:24:12.960 UTC [deliveryClient] try -> WARN 037 Got error: Could not connect to any of the endpoints: [orderer.trace.com:7050] , at 1 attempt. Retrying in 1s

And here is my err message in orderer.trace.com

2021-04-27 06:24:19.576 UTC [core.comm] ServerHandshake -> ERRO 008 TLS handshake failed with error EOF {"server": "Orderer", "remote address": "172.21.0.7:33714"}
1

There are 1 answers

9
Cm Jagtap On

I caught with this issue. It's because your peer1 is down please check using docker ps -a. if it's up then checked its log sometimes due to a memory issue it gets crashes.

also, your transaction will be pushed to the blockchain without any issue. please verify your transaction in the blockchain.