HTTP module orphaning requests.

Posted on
  • Has anyone experienced an issue where your HTTP request is never made? The project I'm working on requests some JSON data on a regular basis (60s) from a server. It works the majority of the time but after it runs for a while, it starts to have issues with orphaned requests. I've run this same code against several different servers, hosts, files, etc... both local and remote and still the same issue.

    Below I have a simple test and if you let this code run for a while, it will eventually start to trip up. I have it set to call every 5 seconds for this test but Increasing the time between calls does not help. I've had it 20, 30 & 60 seconds and still the same issue.

    Beyond it's just my network, does anyone have any thoughts? Thank you!

    let timer = null;
    let WIFI = require("Wifi");
    
    function makeRequest(){
      console.log("GET");
      require("http").request({
        "host":"http://www.espruino.com",
        "path":"/",
        "method":"GET",
      }, function(res) {
        res.on('data', function(data) { });
        res.on('close', function(data) { console.log("CLOSED", res.statusCode); });
      }).end();
    }
    
    WIFI.connect(SSID, { password : PWD }, function(err) {
        if (err) {
            console.log("WIFI ERR",err);
            return;
        }
        console.log("Connected to wifi.");
        makeRequest();        
        
        timer=setInterval(()=>{
          makeRequest();
        },5000);
        
    });
    
  • Hi - did you close this because you found the answer?

    At some point I think on networks - especially WiFi - there will be the occasional failure which you'll need to be able to handle, but there shouldn't be a lot of them.

  • Sorry I was actually looking to delete the post. Right after I posted, I realized it was a stupid question and I didn't want to waste anyones time with it. :)

    It's still happening and but I can live with it and like you said just work around the failures when they happen.

    Sorry about the post.

  • No problem - if there is an issue that's reproducable then there might be something that can be done about it, so it's always good to know :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

HTTP module orphaning requests.

Posted by Avatar for Ken @Ken

Actions