2014-01-17 30 views
0

我正在實施一個節點應用程序,它從BigCommerce帶來詳細的訂單。 使用Restify JsonClient異步地對BigCommerce API進行多次調用。RESTIFY:錯誤:套接字掛斷]代碼:'ECONNRESET'多個請求

它工作正常的一些電話,但我之後給出了錯誤:[Error: socket hang up] code: 'ECONNRESET', sslError: undefined, body: {}

我試圖關閉套接字通過設置agent=false池IE瀏覽器,但它仍然給了同樣的錯誤。

以下是代碼,這使得調用的Bigcommerce API

makeRequest = function (url, params, headers, orderDetails, cb) { 
       var options = { 
       headers: headers 
       }; 

       var client = restify.createJsonClient({ 
        url: url 
       }); 

       client.get(options, function(err, req, res, obj) { 
        if(err){ 
         console.log(err); 
         cb(err,obj); 
        } else if(obj != null) { 
         var result = obj; 
         if(orderDetails == null) { 
          cb(null,result); 
         } else { 
          cb(null, result , orderDetails); 
         } 
        } 
       }); 
      }; 

我獲得以下錯誤:

{ [Error: socket hang up] code: 'ECONNRESET', sslError: unde 
fined, body: {} } Error: socket hang up 
    at SecurePair.error (tls.js:993:23) 
    at EncryptedStream.CryptoStream._done (tls.js:689:22) 
    at CleartextStream.read [as _read] (tls.js:490:24) 
    at CleartextStream.Readable.read (_stream_readable.js:320:10) 
    at EncryptedStream.onCryptoStreamFinish (tls.js:301:47) 
    at EncryptedStream.g (events.js:175:14) 
    at EncryptedStream.EventEmitter.emit (events.js:117:20) 
    at finishMaybe (_stream_writable.js:352:12) 
    at endWritable (_stream_writable.js:359:3) 
    at EncryptedStream.Writable.end (_stream_writable.js:337:5) 
    at EncryptedStream.CryptoStream.end (tls.js:628:31) 
    at Socket.onend (_stream_readable.js:483:10) 

爲什麼會出現這樣的錯誤?我該如何處理它?

感謝

+0

您確定它不是關閉連接的BigCommerce API嗎? – robertklep

回答

1

我只是想確保你在正確的區域設置代理設置。

附上

"agent": false

在你的選擇

。 (這不是在代碼中的選項來設置你粘貼)

每gfpacheco在這裏評論:https://github.com/restify/node-restify/issues/485

By default NodeJS uses agents to keep the TCP connection open, so you can reuse it. The problem is that if the server is closed, or it closes your connection for whatever reason you get the ECONNRESET error.

To close the connection every time you just need to set agent: false in your client creation

我試過這個解決方案,它爲我工作。

除此之外,該

"secureOptions": "constants.SSL_OP_NO_TLSv1_2"

解決方案張貼在這裏聽起來像它可能是正確的道路,因爲你得到的sslError

相關問題