Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iisnode encountered an error when processing the request. - HResult 0x2 - HTTP status: 500 #282

Open
petereysermans opened this issue Jun 13, 2013 · 9 comments

Comments

@petereysermans
Copy link

I can't seem to get iisnode working on my system, my specs:

  • Windows Web Server 2008 R2 x64
  • Node 0.10.10 installed in C:\Program Files (x86)\nodejs
  • iisnode-full-iis7-v0.2.3-x64.msi installed in "C:\Program Files (x86)\iisnode" IISNode is installed via "msiexec /i iisnode-full-iis7-v0.2.3-x64.msi WOW=1"
  • Plesk

The "Enable 32-bit applications" boolean is set to true on the application pool, which runs in Integrated mode (I've tried Classic, does not change anything) and on .Net framework version 4.

My application is the 'Hello world' application that is mentioned in the howtos of iisnode. The code:

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, world! [helloworld sample]');
}).listen(process.env.PORT);  

If I change 'process.env.PORT' to '8000' and run the file via the command 'node hello.js', then the page works fine. I can browse it via localhost:8000. I've looked at the etw traces but can't make anything of it. I've also tried to log any exceptions in my node file by catching the exception and writing it to a file but no file is created.

the etw traces look like this:

  • iisnode initialized the application manager
  • iisnode received a new http request
  • iisnode initialized a new node.exe process
  • iisnode initialized a new node.js application
  • iisnode increases pending async operation count
  • iisnode scheduled a retry of a named pipe connection to the node.exe process
  • iisnode dispatched new http request
  • iisnode decreases pending async operation count
  • iisnode leaves CNodeHttpModule::OnExecuteRequestHandler with RQ_NOTIFICATION_PENDING
  • iisnode detected termination of node.exe process
  • iisnode was unable to establish named pipe connection to the node.exe process before the process terminated
  • iisnode request processing failed for reasons unrecognized by iisnode
  • iisnode decreases pending async operation count
  • iisnode posts completion from SendEmtpyResponse
  • iisnode increases pending async operation count
  • iisnode enters CNodeHttpModule::OnAsyncCompletion callback
  • iisnode decreases pending async operation count
  • iisnode leaves CNodeHttpModule::OnAsyncCompletion with RQ_NOTIFICATION_FINISH_REQUEST

As I didn't find any 'next steps' to take, any help is greatly appreciated.

@tjanczuk
Copy link
Owner

The ETW traces suggest the node.exe process that iisnode creates to serve your application is immediately terminating (iisnode detected termination of node.exe process). I don't see any reason for this in the JavaScript code.

I suggest a few experiments:

  1. Can you try with node.js version 0.8.x?
  2. Add an uncaughtException handler to your server.js and log the exceptions to a file somewhere - let's see if any JS exceptions are thrown.
  3. Is there anythin interesting to be learned from the EventLog?
  4. Can you try installing the just released iisnode v0.2.7? The x64 installer will install both x86 and x64 version of iisnode, and the proper one will be picked up at runtime based on the bitness of the IIS worker process (details in Allow running iisnode 32 and 64 bit side by side on 64 bit servers #281).

@tjanczuk
Copy link
Owner

Also, do any of the node.js samples included with iisnode work?

@petereysermans
Copy link
Author

Thanks for the very quick response!

So I've uninstalled node v0.10.10 and installed v0.8.25, uninstalled iisnode v0.2.6 and installed v0.2.7. I've changed my testfile to this code:

var http = require('http');
var fs = require('fs');

process.on('uncaughtException', function (err) {
    fs.writeFile("test.txt",  err, "utf8");    
})

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, world! [helloworld sample]');
}).listen(process.env.PORT || 8888);  

I think that's the right way of logging an uncaughtException? I'm still at a starting level with node. But nothing is being written to file. I've tested the file writing using the node command directly and the file was written like it should.

There are no events in the event log, and from the samples I've tried 3 (helloworld, defaultdocument and express) all returned the same error.

@tjanczuk
Copy link
Owner

Can you put a simple *.txt file next to your server.js file and try navigating to it from the browser? Let's just make sure the IIS app is set up correctly.

Please change your writeFile to writeFileSync and see if it then writes anything to the file.

Can you add a console.log as the last line in your code (after call to listen) to see if the execution gets that far?

What is the configuration of the IIS application pool that runs your application? Are you doing anything non-default, e.g. custom identity, any other non-default values?

@petereysermans
Copy link
Author

I can browse the text file fine, it shows the content in the browser when I navigate to it. I've changed writeFile to writeFileSync but still nothing is written to file. The console.log is also added to the code, when I run the file with node I can see the message fine. However I don't know where the console.log output is put when running via iisnode. The code now looks like this:

var http = require('http');
var fs = require('fs');

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

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, world! [helloworld sample]');
}).listen(process.env.PORT || 8888);  

console.log('finished');

These are the settings of the application pool, it was created by Plesk when the domain name was created in Plesk:
Basic settings

  • .NET Framework version: .NET Framework v4.0.30319
  • Managed pipeline mode: Integrated

Advanced Settings (I'm only including the ones that are bold)

  • .Net Framework Version: v4.0
  • Enable 32-Bit Applications: True
  • Identity: -custom Plesk identity created for the application pool-
  • Idle Time-out (minutes): 5
  • Load User Profile: False

So to answer your question, the custom identity is indeed non-default. Could that be it?

@petereysermans
Copy link
Author

I've been trying some things with the application pool and its identity, as I had a feeling the problem could be related. I've currently set the application pool to the DefaultAppPool and set the identity to NETWORK SERVICE. After giving NETWORK SERVICE the correct modify rights. I now have an error message:

Application has thrown an uncaught exception and is terminated:
Error: EPERM, operation not permitted 'C:\inetpub\vhosts'
    at Object.fs.lstatSync (fs.js:520:18)
    at Object.realpathSync (fs.js:1047:21)
    at tryFile (module.js:142:15)
    at Function.Module._findPath (module.js:181:18)
    at Function.Module._resolveFilename (module.js:336:25)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (C:\Program Files (x86)\iisnode\interceptor.js:210:1)
    at Module._compile (module.js:449:26)

I'm guessing it is recommended that you run your web application under the DefaultAppPool with the ApplicationPoolIdentity as Identity? However if I tried to set the correct right by adding modify rights to IIS APPPOOL\DefaultAppPool that user wasn't found and when I navigated to the test.js file I just got a 500 - Internal Server Error. So I'm assuming that is a rights problem and the correct rights are not set to the ApplicationPoolIdentity on the iisnode & nodejs folders.

I've found this Server Fault thread but after running the icacls c:\inetpub\wwwroot /grant "IIS APPPOOL\DefaultAppPool":(OI)(CI)(RX) command I keep getting the same 500 - Internal Server Error. Also the following warning is created in the Error Log:

There was an error during processing of the managed application 
service auto-start for application pool: 'DefaultAppPool'.  Some application services may not
have been processed correctly. Please check the configuration for application service 
auto-start for the application(s) assigned to this application pool.  
The data field contains the error code.

@petereysermans
Copy link
Author

I've got it to work with the DefaultAppPool and setting the identity to NETWORK SERVICE. The error above I solved by using the solution you proposed in issue #247.

The only question that remains now is, is it bad to run my application under the NETWORK SERVICE identity? I'm guessing the problem is that the DefaultAppPool is configured in a certain way and the app pools that Plesk creates do not have the same configuration as the DefaultAppPool?

@futurechan
Copy link

+1

@vinogeetha
Copy link

simple, give access-control-allow-origin in node server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants