0

I have a client application build on ASP.net and backed in Nodejs & express, hosted on IIS version 10 in window server 2016. when I sent a post request with large data in request body to an API end point it return net::ERR_CONNECTION_RESET error in browser console after 2 minute. this was working fine earlier and suddenly it started giving this error. it is working fine when I pass small data in request body but when it is more than 320 then its not hitting the end point and giving an error message on console net::ERR_CONNECTION_RESET after 2 minute.

  1. Data that pass into the request body
[{ProductId: "352561", Country: "United State"}, {ProductId: "364321", Country: "China"}]
[0 … 99]
[100 … 199]
[200 … 299]
[300 … 302]
  1. Aspx page from where I am making the request to an api end point
makePostRequest('http://localhost:3000/searchMultiple', tableData);

async function makePostRequest(path, tableData) {
        const result = await fetch(path, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(tableData)
        });
        //console.log(result);
        const data = await result.json();
}
  1. Node API end point
app.post('/searchMultiple', (request, response) => {

    tableData = request.body;
    if (tableData.length > 0) {

        searchMultipleProduct(tableData)
            .then(results => {
                //Returns a 200 Status OK with Results JSON back to the client.
                response.status(200);
                response.json(results);
            });
    } else {
        response.end();
    }
});
  1. server side web config file IISNode
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
            <rules>
                    <rule name="nodejs">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="" ignoreCase="true" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="server.js" />
                    </rule>
            </rules>
        </rewrite>
     
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="4294967295"  />
                <hiddenSegments>
                    <add segment="node_modules" />
                    <add segment="iisnode" />
                </hiddenSegments>
            </requestFiltering>
        </security>
        
    </system.webServer>
</configuration>
  1. Client side web config file
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization" />
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
      </controls>
    </pages>
  </system.web>
    <system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="2147483647" />
            </webServices>
        </scripting>
    </system.web.extensions>
</configuration>

Any help / pointers / links / whatever would be greatly appreciated.

1 Answers1

0

I think your issue may be within the POST : /searchMultiple route.

app.post('/searchMultiple', (request, response) => {

    tableData = request.body;
    if (tableData.length > 0) {

        searchMultipleProduct(tableData)
            .then(results => {
                //Returns a 200 Status OK with Results JSON back to the client.
                response.status(200);
                response.json(results);
            });
    } else {
        response.end();
    }
});

This will help you narrow down whether or not the issue is with your database connection. Since CONNECTION RESET means the response took longer than the IIS timeout, you can start with increasing your IIS timeouts or you may just need to add a catch statement to your async searchMultipleProduct function.. Adding the catch statement may help with sending a response on error (if that error is due to large data, now you will be able to tell due to the error response).

app.post('/searchMultiple', (request, response) => {

    tableData = request.body;
    if (tableData.length > 0) {

        searchMultipleProduct(tableData)
            .then(results => {
                //Returns a 200 Status OK with Results JSON back to the client.
                response.status(200);
                response.json(results);
            }).catch(err => {
                resp.status(500).send(err));
            });
    } else {
        response.end();
    }
});
Matt Oestreich
  • 8,219
  • 3
  • 16
  • 41
  • Hi Matt - I have tried you approach, increasing the timeout in IIS 10 from 120 sec to 240 sec but if I pass the data in request body more than 300 items, it is not hitting the api endpoint. In reverse, when I pass the data less than 250 item and it's works fine. I don't have database dependency in application. I have checked the logs in IIS 10 and it is showing sc-status - 200. I am not sure what is happening in background. – rahsinha Jun 14 '21 at 08:21