azure-functions-host: Azure Functions: Node.js: Request ~2.34.0 not working

Referring back to #226 and #223. The node module Request version 2.34.0 is not working on Azure Functions. Packages such as YQL are depending on it. Request version 2.70.0 is working correctly on Azure Functions. The below code snippet is working fine on request version 2.70.0, on version 2.34.0, however, the callback is never called.

var request = require('request');

module.exports = function (context) {  
    request('http://www.bing.com', function (error, response, body) {
        // This callback function will never be called on version 2.34.0
        if (error) {
            context.log(error);
        }

        if (!error && response.statusCode == 200) {
            context.log(body) // Show the HTML for the Bing homepage. 
        }
        context.done();
    });
};

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 20 (13 by maintainers)

Most upvoted comments

I’ve done some investigating here – the specific commit to request that fixes things is here: https://github.com/request/request/commit/27dfc1177e01025da6d3b09a0fd3406b90596719.

The issue looks to be around calling process.nextTick from Edge. Executing this code in Edge.Func() hangs as well:

return function(arg, callback) {
  process.nextTick(function() {
      console.log('done');
      callback();
  });
};

If you replace process.nextTick with setImmediate, things work. I see others reporting the same thing over at the Edge repo: https://github.com/tjanczuk/edge/issues/325. I’ll see if there’s a workaround or fix for this – otherwise, it appears that any package that uses process.nextTick will hang.

PR #486 works around this issue. If you want to get things working before this change is deployed to production, you can add this to the your code before you make the call to request: process.nextTick = global.setImmediate;

So one way to get this working is to replace process.nextTick: process.nextTick = global.setImmediate;

That seems pretty gnarly, but gets this sample working. Would any node experts care to berate me for this workaround? 😃