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

Thread-local feature does not really work. #51

Open
goodjius opened this issue Mar 6, 2016 · 0 comments
Open

Thread-local feature does not really work. #51

goodjius opened this issue Mar 6, 2016 · 0 comments

Comments

@goodjius
Copy link

goodjius commented Mar 6, 2016

The following express example just added a setTimeout on the route. If sending two request at the same time, for example, chrome and firefox.
Notice the console log of the requestId are both 2.
Also, this library does not work with the latest nodejs.
With node 0.12.03, it occationally got the following error.

TypeError: Cannot read property '_incrementScheduledTaskCount' of undefined
at TCP.prototype.close (/home/gitadmin/pms/node_modules/zone/lib/wrappers/binding/stream-wrap.js:429:22)
at Socket._destroy (net.js:483:18)
at Socket.destroy (net.js:510:8)
at Socket.onSocketFinish (net.js:226:17)
at Zone.apply (/home/gitadmin/pms/node_modules/zone/lib/zone.js:617:15)
at ZoneCallback.call as apply
at Socket.wrapper (/home/gitadmin/pms/node_modules/zone/lib/zone.js:761:21)
at Socket.emit (events.js:104:17)
at Zone.apply (/home/gitadmin/pms/node_modules/zone/lib/zone.js:617:15)
at Socket.emit (events.js:382:21)

require('zone').enable();
express = require('express');
var Zone = zone.Zone;

var app = express();
var router = express.Router();
Zone.longStackSupport = true;

//Initialize the Request id in the root zone.
//This value will be available to all child zones.
zone.data.requestId = 0;

app.use(function(req, res, next) {
//Increment the request ID for every new request
++zone.data.requestId;

//Create a new Zone for this request
zone.create(
function RequestZone() {
//Store the request URL in the Request zone
//This value will be only to this zone and its children
zone.data.requestURL = req.url;

         //Continue to run other express middleware within this child zone
         next();
       })
  .setCallback(function(err,result) {
     if (!err) {
        res.write('Transaction succesful\n');
     } else {
        res.write('Transaction failed\n');
        res.write('x' + err.zoneStack + '\n');
     }
     res.end();
  });

});
router.get('/', function(req, res) {
setTimeout(function(){
if (Math.random() > 0.5) {
//Simulate some async I/O call that throws an exception
process.nextTick(function() { throw new Error("monkey wrench"); });
}

res.write('Running request #' + zone.data.requestId + ' within zone: ' +
zone.name + ' (URL:' + zone.data.requestURL + ')\n');
}, (zone.data.requestId %2 ?10:5 )* 1000);
});

app.use('/', router);
app.listen(3001);

@goodjius goodjius changed the title Thread-local feature does not really works. Thread-local feature does not really work. Mar 6, 2016
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

1 participant