Skip to content

Thread-local feature does not really work. #51

@goodjius

Description

@goodjius

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions