wanasit / google-calendar

Google Calendar API connection in Node.js
MIT License
230 stars 54 forks source link

Cannot set headers after they are sent and Error Socket Hang Up issue #22

Closed chetanku closed 6 years ago

chetanku commented 6 years ago

I am using async.each to insert events into google calendar. I am not sure if I am implementing it the right way it is supposed to, can you please help? I am using the latest versions, updated node to 8.x to see if it fixes the issue but it didnt.

async.each(req.dates,function(value,callback){

var google_calendar = new gcal.GoogleCalendar(req.user.accessToken);
google_calendar.events.insert(req.gmailid,event, function(err,data) { if (err) { console.log(err); callback(err) return; } else{
console.log(data); callback(); } });
},function (err){ if (err){ console.log(err); res.send('THIS IS THE CULPRIT '+ err); } else { console.log(googleResponse); res.sendStatus(200).send("Reminder added SuccessFully"); } }) }); I get Cannot set headers after they are sent in the terminal

and this from the debug session. null: Error: socket hang up null: Error: socket hang up code: "ECONNRESET" message: "socket hang up" stack: "Error: socket hang up at createHangUpError (_http_client.js:331:15) at TLSSocket.socketCloseListener (_http_client.js:363:23) at emitOne (events.js:121:20) at TLSSocket.emit (events.js:211:7) at Socket._destroy.cb._handle.close (net.js:554:12) at TCP.done [as _onclose] (_tls_wrap.js:356:7)" proto: Object {constructor: , name: "Error", message: "", …} constructor: function Error() { … } BluebirdErrorTypes: Object {CancellationError: , TimeoutError: , OperationalError: , …} arguments: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them caller: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them captureStackTrace: function captureStackTrace() { … } arguments: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them caller: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them length: 2 name: "captureStackTrace" proto: function () { … } length: 1 name: "Error" prepareStackTrace: undefined prototype: Object {constructor: , name: "Error", message: "", …} constructor: function Error() { … } BluebirdErrorTypes: Object {CancellationError: , TimeoutError: , OperationalError: , …} arguments: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them caller: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them captureStackTrace: function captureStackTrace() { … } length: 1 name: "Error" prepareStackTrace: undefined prototype: Object {constructor: , name: "Error", message: "", …} stackTraceLimit: 16 proto: function () { … } message: "" name: "Error" toString: function toString() { … } proto: Object {constructor: , defineGetter: , defineSetter: , …} stackTraceLimit: 16 proto: function () { … } message: "" name: "Error" toString: function toString() { … } arguments: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them caller: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them length: 0 name: "toString" proto: function () { … } proto: Object {constructor: , defineGetter: , defineSetter: , …} In the Post gCal

null: Error: socket hang up

null: Error: socket hang up

chetanku commented 6 years ago

I resolved this issue by updating the needle package to latest (2.0.1) in google-calendar and it worked. I only found this issue when doing multiple async calls.