It is doing some IO call to update try_count in DB. Which may fail.
On Monday, July 29, 2013 2:16:42 PM UTC+5:30, Floby wrote:
>
> Why is your error-handling function not safe ?
>
> On Friday, 26 July 2013 17:42:51 UTC+2, Vivek Goel wrote:
>>
>> I am using a third party library. Which is using node domain for error
>> handling. If the callback function passed to that third party library have
>> any error, It end-up in calling my callback multiple times.
>>
>> Example code is:
>> //Read this code from bottom to top
>>
>> var startFunction = function (callback) {
>>
>> //Call thirdParty function and wait for response
>> thirdPartyFunction(function (error, data) {
>> console.log("Called with");
>> console.log(arguments);
>>
>> //Assume there is an error in my callback function
>> setTimeout(function () {
>> dd
>> callback.apply(null);
>> }, 2000);
>> });
>>
>> }
>>
>>
>> //ThirdParty function don't modify anything here
>> var thirdPartyFunction = function (callback) {
>> var Domain = require("domain");
>>
>> var domain = Domain.create();
>> var d = require('domain').create();
>>
>> d.on('error', function (er) {
>> console.log("hi");
>> callback.apply(null, er);
>> });
>>
>> d.run(function () {
>>
>> setTimeout(function () {
>> callback.apply(null, [null, "Hello"]);
>> }, 1000);
>>
>>
>> });
>> }
>>
>> //Call Start function and wait for response
>> startFunction(function () {
>> console.log("Got response")
>> });
>>
>> We reported this bug to third party lib and they have modified the source
>> code. Like:
>>
>> d.on('error', function (er) {
>>
>> if (isCalled == false) {
>> isCalled = true;
>> } else {
>> return;
>> }
>>
>> console.log("hi");
>> callback.apply(null, er);
>> });
>>
>> Now problem of function getting called multiple times is solved. But
>> final callback is never getting called.
>>
>> How to handle this behavior of node ?
>>
>> If third party lib modify there code to, It result in application crash.
>> Putting a wrapper domain also not help.
>>
>> d.on('error', function (er) {
>>
>> if (isCalled == false) {
>> isCalled = true;
>> } else {
>> throw new Error("Getting called");
>> return;
>> }
>>
>> console.log("hi");
>> callback.apply(null, er);
>> });
>>
>>
>> What is the best method of handing such cases in node ?
>> What I want is startFunction should come back in all cases.
>>
>>
>>
>>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.