none
[Node.js][Web Apps] How can I configure IIS to stream chunked data from a Node.js app? RRS feed

  • Question

  • I have a Node.js app that uses Transfer-Encoding: Chunked to stream data over HTTP continuously until the client disconnects. When running a local instance of Node, it works fine, but when deployed to Azure, client connections hang without ever receiving data.

    Logging indicates that the Node app is processing requests and streaming data correctly, but for some reason that data is not reaching the client.

    Here's a simplified example of the way I'm streaming data from Node:

    var server = http.createServer();
    server.on('request', function(request, response) {
        var interval = setInterval(function() {
            response.write("some data\r\n");
        }, 1000);
        request.on('close', function() {
            clearInterval(interval);
        });
    });

    In my iisnode.yml config file I have set flushResponse: true to prevent iisnode from buffering response chunks.

    My guess is that IIS is trying to buffer the entire response before sending it, but I don't know how to disable this behavior.



    Friday, May 13, 2016 7:47 PM

Answers

  • Hi andrewwatt,

    In my test project, beside configuring 

    flushResponse:true

    in iisnode.yml, please try to add the response header to make your response output data in steam chunked:

    var http = require('http');
    var server = http.createServer();
    server.on('request', function(request, response) {
        response.setHeader('Connection', 'Transfer-Encoding');
        response.setHeader('Content-Type', 'text/html; charset=utf-8');
    	response.setHeader('Transfer-Encoding', 'chunked');
        var interval = setInterval(function() {
            response.write("hit interval: "+ new Date());
        }, 1000);
        request.on('close', function() {
            clearInterval(interval);
        });
    });
    server.listen(process.env.PORT, function(){})

      Any further concern, please feel free to let me know.
    Monday, May 16, 2016 7:22 AM
    Moderator

All replies

  • Hello,

    Thank you for posting here!

    You can try to disable IIS bufferring by setting the responseBufferLimit to 0 as below,

    <add name="iisnode" path="app.js" verb="*" modules="iisnode" responseBufferLimit="0" />

    And also, I have found one discussion on the similar query. Please refer this and let us know the status.

    Hope this helps.


    Regards,

    Swikruti

    If a post answers your question, please click Mark as Answer on that post and Vote as Helpful.
    Saturday, May 14, 2016 1:42 PM
  • Thanks for the suggestion. Unfortunately I already do have responseBufferLimit set to 0 and it didn't seem to have any effect.
    Saturday, May 14, 2016 6:11 PM
  • Hi andrewwatt,

    In my test project, beside configuring 

    flushResponse:true

    in iisnode.yml, please try to add the response header to make your response output data in steam chunked:

    var http = require('http');
    var server = http.createServer();
    server.on('request', function(request, response) {
        response.setHeader('Connection', 'Transfer-Encoding');
        response.setHeader('Content-Type', 'text/html; charset=utf-8');
    	response.setHeader('Transfer-Encoding', 'chunked');
        var interval = setInterval(function() {
            response.write("hit interval: "+ new Date());
        }, 1000);
        request.on('close', function() {
            clearInterval(interval);
        });
    });
    server.listen(process.env.PORT, function(){})

      Any further concern, please feel free to let me know.
    Monday, May 16, 2016 7:22 AM
    Moderator
  • Thanks. I tried this but unfortunately I still get the same result: no data to the client.
    Monday, May 16, 2016 4:08 PM
  • Do you have any other configurations? Could you please build up with a new clean Azure Web Apps with nodejs, and try again? Because it works fine on my side by visiting via browser.
    Tuesday, May 17, 2016 12:58 AM
    Moderator
  • How are you testing it with a web browser? It's designed to be consumed by a client that does not close the connection. I have been using curl to connect, which shows exactly what data is sent and received, and will never time out.
    Tuesday, May 17, 2016 11:12 PM
  • I directly browse the Node.js application in browser. However, if you are looking for a persistent connection to Node.js backend, I think you can use webSocket. Please refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-chat-app-socketio/ for more. 
    Wednesday, May 18, 2016 1:18 AM
    Moderator