EADDRNOTAVAIL after many http.get requests to localhost

后端 未结 2 1411
猫巷女王i
猫巷女王i 2020-12-31 10:54

When doing many http.get-requests to localhost (Apache) after 28233 requests I get EADDRNOTAVAIL.

When broken:

  • I cannot do
相关标签:
2条回答
  • 2020-12-31 11:57

    I have found the solution by overwriting the default global agent. One possibility is to set maxSockets:1:

    var http = require( "http"),
        agent = new http.Agent( {maxSockets: 1} ); // <-- this is new
    
    function httpRequest( callback ) {
        var options = {
                host: 'localhost',
                port: 80,
                path: '',
                agent: agent // <-- and this is new
            },
    ...
    

    With this correction the example above works. But I still had the EADDRNOTAVAIL issue within my production code, so setting the agent to false did it finally:

    var http = require( "http");
    
    function httpRequest( callback ) {
        var options = {
                host: 'localhost',
                port: 80,
                path: '',
                agent: false // <-- here
            },
    ...
    

    I have posted this issue also on GitHub.

    0 讨论(0)
  • 2020-12-31 11:59

    MacOS solution , or at least what worked for me

    and sending the request to mac.local

    0 讨论(0)
提交回复
热议问题