3

iisnode encountered an error when processing the request.

HRESULT: 0x2 HTTP status: 500 HTTP subStatus: 1001 HTTP reason: Internal Server Error

This is a fairly simple node/express application which we cannot get to run under iisnode.

We are seeing errors in the ETW trace such as: iisnode request processing failed for reasons unrecognized by iisnode iisnode was unable to establish named pipe connection to the node.exe process

The last thing seen in the node output is: server Express http server listening on port \.\pipe\15524b7e-249a-4464-b41a-eddab028342e

Where can we look to find out what is happening?

1) the node application works correctly from the command line in the folder, by typing node server.js. 2) There is seemingly nothing "thrown" in the javascript, we have this code:

process.on('uncaughtException', function (err) {
    console.log(err);
    fs.writeFileSync("exception.txt", err, "utf8");
})

3) the web.config is as follows:

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <system.webServer>
    <handlers>
      <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>

        <rule name="NodeLog">
          <action type="Rewrite" url="iisnode{REQUEST_URI}"/>
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="server.js"/>
        </rule>
      </rules>
    </rewrite>

    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
          <add segment="node_modules"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
    <defaultDocument enabled="true">
      <files>
        <add value="server.js" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>

The server.js is pretty simple:

var fs = require('fs');
var express = require('express');
var path = require('path');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var methodOverride = require('method-override'); // Lets you use HTTP verbs such as PUT or DELETE in places where the client doesn't support it.

var routes = require('./routes/index');

var http = require('http');
var https = require('https');
var options = {
    pfx: fs.readFileSync(path.join(__dirname, 'sslcert') + '/web.local.pfx'),
    passphrase: ''
}

var app = express();

//app.engine("ejs", ejsEngine); // templating engine

// must set up environment before controllers establish routes

// all environments
// set default port if not set
//app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));

// opt into services
app.use(express.static(path.join(__dirname, 'public')));

app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: false }));

app.use(bodyParser.json());
app.use(methodOverride());

/* api access */
app.get('/api', function (req, res) {
    res.send('api is up and running');
});

//app.get('*', function (req, res) {
//    res.render('index.html');
//});

var port = process.env.PORT || 3000;

// start the web server
http.createServer(app).listen(app.get(port), function () {
//http.createServer(app).listen(2025, function () {
    console.log('server', 'Express http server listening on port' + port);
});

https.createServer(options, app).listen(8443, function () { 
    console.log('server', 'Express https server listening on port 8443');
});

module.exports = app;
pinnprophead
  • 215
  • 3
  • 14
  • We tried to use iisnode when we first decided to run a node app on our windows server, however, ended up opting for using a reverse proxy instead and running the node server as a service to avoid having to deal with iis integrating with our node process. – Kevin B Jul 29 '15 at 20:46
  • As far as your problem, it looks like more of a iisnode issue than node, unless your node app is exiting and somehow missing the uncaughtException handler. – Kevin B Jul 29 '15 at 20:47
  • How are you starting your server? (i'm looking for javascript code, such as `if (require.main === module) { start(); }`) – Kevin B Jul 29 '15 at 21:00
  • 1001 in this case means: "Recursion too deep; the stack overflowed." you can get that msg yourself using `net helpmsg 1001` though that message doesn't really help much. – Kevin B Jul 29 '15 at 21:06
  • @Kevin B see the server.js I posted. Not much to it. – pinnprophead Jul 30 '15 at 20:41
  • Did you get this figured out? – Erik Grosskurth Nov 18 '16 at 14:53
  • No -- we gave up. – pinnprophead Dec 05 '16 at 13:25

1 Answers1

2

I had the same issue with IISNode and spent far too much time trying to fix it. I tried adding different permissions for different users (IIS_USRS, IUSRS, Everyone, IIS AppPool/domainname) through Windows explorer with no luck.

I finally found the solution in the setupexamples.bat script, provided with the iisnode examples. Simple run the following script on the folder containing your app code:

icacls (folder_name) /grant IIS_IUSRS:(OI)(CI)F /t
Lucas
  • 41
  • 5
  • I run setupexamples.bat but I can't figure out what to do now,that code gives error execution – O.Rares Jul 19 '17 at 13:35
  • I don't run the actual setupexamples.bat script; I used parts of the script as an example how to set correct permissions. Just run the command mentioned above on the folder which contains your app. – Lucas Jul 20 '17 at 07:31
  • I tried all combination of web.config and nothing works,4 days I spent in a row to solve this,still no chance to find the solution – O.Rares Jul 20 '17 at 10:12
  • Have you tried setting the permissions (recursively) for the folder containing the app through Windows explorer? I usually set the permissions to Full Access for Everyone, then I run the icalcs command above – Lucas Jul 20 '17 at 12:16