简体   繁体   English

Azure移动服务发生未处理的异常。 错误:您的一个脚本导致服务无响应

[英]Azure Mobile Services An unhandled exception occurred. Error: One of your scripts caused the service to become unresponsive

Apologize for my English. 为我的英语道歉。

I have a node js script that has to send AMQP messages to device using IoT hub. 我有一个节点js脚本,必须使用IoT中心将AMQP消息发送到设备。 I've took thiss script from github of azure iot. 我已经从azure iot的github上获取了此脚本。 Here is this sample. 这是这个样本。

Here is this sample 这是这个样本

Here is my script, based on this one: 这是基于此脚本的脚本:

    console.log("creating the client");

var Client = require('azure-iothub').Client;
console.log("client has been created");

var Message = require('azure-iot-common').Message;
console.log("message has been created");


var connectionString = "HostName=id**.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=***;
console.log(connectionString);
var targetDevice = 'devicesergey';

var client = Client.fromConnectionString(connectionString);

client.open(function (err) {
    if (err) {
        console.error('Could not connect: ' + err.message);
    } 
    else {
        console.log('Client connected');

        var data = JSON.stringify({ text : 'foo' });
        var message = new Message(data);
        console.log("json message is created")
        console.log('Sending message: ' + message.getData());
        client.send(targetDevice, message, printResultFor('send'));
        console.log("message has been sent");             
    }
});

function printResultFor(op) {
  return function printResult(err, res) {
    if (err) {
      console.log(op + ' error: ' + err.toString());
    } else {
      console.log(op + ' status: ' + res.constructor.name);
    }
  };
} 

That works fine locally and I see messages on my device emulator. 在本地运行正常,我在设备模拟器上看到消息。 But when I try to put it to Azure Mobile Services API and try to run it, I see this message on logs: 但是,当我尝试将其放入Azure移动服务API并尝试运行它时,我在日志中看到以下消息:

An unhandled exception occurred. 发生未处理的异常。 Error: One of your scripts caused the service to become unresponsive and the service was restarted. 错误:您的脚本之一导致服务无响应,并重新启动了服务。 This is commonly caused by a script executing an infinite loop or a long, blocking operation. 这通常是由脚本执行无限循环或长时间的阻塞操作引起的。 The service was restarted after the script continuously executed for longer than 5000 milliseconds. 脚本连续执行超过5000毫秒后,服务重新启动。 at process.Server._registerUncaughtExceptionListenerAndCreateHttpServer._onUncaughtException (D:\\home\\site\\wwwroot\\node_modules\\azure-mobile-services\\runtime\\server.js:218:17) at process.EventEmitter.emit (events.js:126:20) 在process.EventEmitter.emit(events.js:126:20)上的Server._registerUncaughtExceptionListenerAndCreateHttpServer._onUncaughtException(D:\\ home \\ site \\ wwwroot \\ node_modules \\ azure-mobile-services \\ runtime \\ server.js:218:17) )

And sometimes I see this IIS error I know exactly that this line occurs this function: client.open(function.... I've evem tried to leave only client.open() and send a messages out of this function. But in this case I see "client is not connected". 有时我看到此IIS错误,我确切地知道此行发生此功能:client.open(function ....我已经尝试仅离开client.open()并从该函数发送消息。在这种情况下,我看到“客户端未连接”。

I asked about this stuff on github. 我在github上问了这些东西。 They advised me to asked here. 他们建议我在这里问。 Maybe someone know how to solve this issue (with script or Azure). 也许有人知道如何解决此问题(使用脚本或Azure)。 I would be very very greatfull! 我会非常非常高兴!

Thank you! 谢谢!

The Mobile Service Custom API is a script that expose the functionality of the express.js library, please see the section Overview of custom APIs of the offical document "Work with a JavaScript backend mobile service" 移动服务自定义API是用于展示express.js库功能的脚本,请参阅官方文档“使用JavaScript后端移动服务” Overview of custom APIs部分

I reproduced the issue successfully. 我已成功复制了该问题。 I guess your script was not wrapped in the code below as the body block, and not sent the response to the client like browser. 我猜您的脚本没有作为主体块包装在下面的代码中,并且没有将响应发送给客户端(如浏览器)。

exports.get = function(request, response) {
    // The body block
    ....
    response.send(200, "<response-body>");
}

For more details of Mobile Service Custom API, please see https://msdn.microsoft.com/library/azure/dn280974.aspx . 有关移动服务自定义API的更多详细信息,请参阅https://msdn.microsoft.com/library/azure/dn280974.aspx


Update : 更新

I changed your code as below. 我如下更改了您的代码。 在此处输入图片说明

And In order to facilitate the test, I changed the permission for the api as below, then I can access the api link https://<mobile-service-name>.azure-mobile.net/api/test with browser. 为了方便测试,我如下更改了api的权限,然后可以使用浏览器访问api链接https://<mobile-service-name>.azure-mobile.net/api/test 在此处输入图片说明

I've just tried to execute my script on new Azure MS and it was unsuccesfully. 我刚刚尝试在新的Azure MS上执行脚本,但未成功。 I will write my step-by-step actions, maybe you can see anything wrong, because I'm not so good in NodeJS. 我将编写分步操作,也许您会发现任何错误,因为我对NodeJS的了解不佳。

  1. Add a new Azure MS with new SQL Database 使用新的SQL数据库添加新的Azure MS
  2. Add a new API "dev". 添加一个新的API“ dev”。 Access - everyone for all points. 访问-每个人都可以。 Here is source code: 这是源代码:

     exports.get = function(request, response) { console.log("creating the client"); var Client = require('azure-iothub').Client; console.log("client has been created"); var Message = require('azure-iot-common').Message; console.log("message has been created"); var connectionString = "HostName=i***.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey***"; console.log(connectionString); var targetDevice = 'devicesergey'; var client = Client.fromConnectionString(connectionString); client.open(function (err) { if (err) { console.error('Could not connect: ' + err.message); } else { console.log('Client connected'); var data = JSON.stringify({ text : 'foo' }); var message = new Message(data); console.log("json message is created") console.log('Sending message: ' + message.getData()); client.send(targetDevice, message, printResultFor('send')); console.log("message has been sent"); } }); response(200, "Hello, world!"); }; function printResultFor(op) { return function printResult(err, res) { if (err) { console.log(op + ' error: ' + err.toString()); } else { console.log(op + ' status: ' + res.constructor.name); } }; } 

If I try to execute this stuff it occurs "no azure-iothub" and "no azure-iot-common", so I need to use git to add these npm. 如果我尝试执行这些内容,则会出现“ no azure-iothub”和“ no azure-iot-common”,因此我需要使用git来添加这些npm。

  1. I clone this repository to my local dir using git access to Azure MS https://id .scm.azure-mobile.net/id .git 我使用对Azure MS https:// id .scm.azure-mobile.net / id .git的git访问权限将此存储库克隆到本地目录
  2. Enter the "API" folder and add the NPMs: 输入“ API”文件夹并添加NPM: npm安装

  3. Then I perfom "Rescan", "Save changes", "Commit", "Push" on 然后我执行“重新扫描”,“保存更改”,“提交”,“推送”

  4. After these actions I execute my script by path " http://id **.mobile-services.net/api/dev" and don't see anything o see the error "500.1013" and these messages on logs (id depends): 完成这些操作后,我通过路径“ http:// id **。mobile-services.net/api/dev”执行脚本,看不到任何东西,看到错误“ 500.1013”,并且这些消息在日志中显示(id取决于) :

An unhandled exception occurred. 发生未处理的异常。 Error: One of your scripts caused the service to become unresponsive and the service was restarted. 错误:您的脚本之一导致服务无响应,并重新启动了服务。 This is commonly caused by a script executing an infinite loop or a long, blocking operation. 这通常是由脚本执行无限循环或长时间的阻塞操作引起的。 The service was restarted after the script continuously executed for longer than 5000 milliseconds. 脚本连续执行超过5000毫秒后,服务重新启动。 at process.Server._registerUncaughtExceptionListenerAndCreateHttpServer._onUncaughtException (D:\\home\\site\\wwwroot\\node_modules\\azure-mobile-services\\runtime\\server.js:218:17) at process.EventEmitter.emit (events.js:126:20) 在process.EventEmitter.emit(events.js:126:20)上的Server._registerUncaughtExceptionListenerAndCreateHttpServer._onUncaughtException(D:\\ home \\ site \\ wwwroot \\ node_modules \\ azure-mobile-services \\ runtime \\ server.js:218:17) )

I can't realize what I'm doing wrong 我不知道我在做什么错

UPDATE: I've tried to use Kudu console for installing the npms and it returns many errors. 更新:我试图使用Kudu控制台安装npms,它返回许多错误。 If i figured out correctly, I need to update my node js and npm. 如果我正确找出,我需要更新我的节点js和npm。 But I don't know how to do this and I didn't manage to find a solution. 但是我不知道该怎么做,也没有找到解决方案。 Here are logs: 这是日志: 在此处输入图片说明 I have lack of reputation, so I am not allowed to past log scripts. 我缺乏声誉,因此不允许我过去使用日志脚本。

I've tried to do these actions, but it doesn't help: 我已尝试执行以下操作,但无济于事:

at the root of the repo, you'll find a .deployment file that has: 在仓库的根目录下,您将找到一个.deployment文件,该文件具有:

command = ..\\ZumoDeploy.cmd Change it to 命令= .. \\ ZumoDeploy.cmd更改为

command = deploy.cmd And create a deploy.cmd next to it containing: 命令= deploy.cmd并在其旁边创建一个deploy.cmd,其中包含:

set NPM_JS_PATH=%ProgramFiles(x86)%\\npm\\1.4.9\\node_modules\\npm\\bin\\npm-cli.js ..\\ZumoDeploy.cmd Commit both files and push. set NPM_JS_PATH =%ProgramFiles(x86)%\\ npm \\ 1.4.9 \\ node_modules \\ npm \\ bin \\ npm-cli.js .. \\ ZumoDeploy.cmd提交文件并推送。

I'm confused. 我糊涂了。 How is it possible? 这怎么可能? Azure Mobile services don't permit to install azure-iot-hub npm). Azure移动服务不允许安装azure-iot-hub npm)。 What can I do with this issue? 该问题我该怎么办?

UPDATE2: Peter Pan - MSFT, you advised me to use Kudu DebucConsole to install necessary npm. UPDATE2: Peter Pan-MSFT,您建议我使用Kudu DebucConsole安装必要的npm。 But when I try to do it - I see errors. 但是,当我尝试这样做时-我看到了错误。

I've messaged about this issue to "npm" command on github, they say that the version of npm which Azure is used to - is completely unsupported. 我已经将此消息告知github上的“ npm”命令,他们说Azure过去使用的npm版本完全不受支持。 htt ps://github.com/npm/npm/issues/12210#event-615573997 htt ps://github.com/npm/npm/issues/12210#event-615573997

UPDATE3 (04/12/2016) I've solved this issue by different way. UPDATE3(04/12/2016)我已经通过不同的方式解决了这个问题。 Created my own node JS script that is listening a port, read GET params(deviceId and message) and send D2C messages. 创建了我自己的侦听端口的节点JS脚本,读取GET参数(deviceId和message)并发送D2C消息。 Unfortunately, I still can't get trow the Azure issue. 不幸的是,我仍然无法解决Azure问题。

UPDATE4 Peter Pan gave me an advise how to use another version of nodejs and npm. UPDATE4 Peter Pan给了我一个建议,如何使用另一个版本的nodejs和npm。 Now I've succesfully installed necessary NPM modules. 现在,我已经成功安装了必要的NPM模块。 But now Azure Mobile Script APIs don't work, it shows me {"code":404,"error":"Error: Not Found"} on any script that I try to get in my browser. 但是现在Azure移动脚本API无法正常工作,它显示了我尝试在浏览器中获取的任何脚本上的{“ code”:404,“ error”:“ Error:Not Found”}。

Maybe I've deleted something when I tried to do these stuffs. 尝试执行这些操作时,也许删除了某些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 本地Azure移动服务/应用服务 - Azure Mobile Service/App Services On-Premises 由于发生内部服务器错误,无法显示该页面。 Node.js 天蓝色 - The page cannot be displayed because an internal server error has occurred. Node.js azure AggregateException:发生一个或多个错误。 (发生一个或多个错误。(无法启动“npm”。要解决此问题: - AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this: 每2分钟ECONNREFUSED天蓝色移动服务错误 - azure mobile services error ECONNREFUSED every 2 mins 将使用哪个用于节点移动服务的Azure SDK脚本/在哪里记录? - Which Azure SDK for Node Mobile Service scripts is to be used / where is it documented? 运行 ng serve 发生未处理的异常 - Unhandled exception occurred running ng serve 发生未处理的异常:找不到模块“./browsers”- - An unhandled exception occurred: Cannot find module './browsers' - 错误:发生意外错误。 Firebase功能 - Error: An unexpected error has occurred. Firebase Functions Firebase HelloWorld的云功能“错误:发生意外错误。” - Cloud Functions for Firebase HelloWorld “Error: An unexpected error has occurred.” Firebase Cloud Function 部署时出现“错误:发生意外错误”。 - Firebase Cloud Function deploy with "Error: An unexpected error has occurred."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM