I have a server side method for authenticating against a Microsoft Active Directory server using LDAP. This works nicely, but I can’t get the result back to the client - apparently the bind call is async and hence I am returning before the response is back. So as I understand Meteor methods, I should simply return a Promise and that will then be resolved by the Meteor call. How to do that?
W20181207-15:47:36.517(1)? (STDERR) (node:28423) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
W20181207-15:47:36.569(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:594:27)
W20181207-15:47:36.569(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-15:47:36.569(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-15:47:36.570(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-15:47:36.570(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-15:47:36.570(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-15:47:36.570(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-15:47:36.570(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-15:47:36.570(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-15:47:36.570(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-15:47:36.570(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-15:47:36.571(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-15:47:36.571(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-15:47:36.571(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-15:47:36.571(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-15:47:36.571(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-15:47:36.571(1)? (STDERR) (node:28423) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
W20181207-15:47:36.571(1)? (STDERR) (node:28423) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
OK, now I get the BindResponse printed to console server side, but then I get:
W20181207-16:21:21.565(1)? (STDERR) (node:28726) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
W20181207-16:21:21.565(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:594:27)
W20181207-16:21:21.565(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-16:21:21.565(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-16:21:21.565(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-16:21:21.566(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-16:21:21.566(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-16:21:21.566(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-16:21:21.566(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-16:21:21.566(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-16:21:21.566(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-16:21:21.566(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-16:21:21.566(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-16:21:21.567(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-16:21:21.567(1)? (STDERR) at Array.forEach (<anonymous>)
W20181207-16:21:21.567(1)? (STDERR) at Object.EJSON.clone.v [as clone] (packages/ejson/ejson.js:594:18)
W20181207-16:21:21.567(1)? (STDERR) at Object.keys.forEach.key (packages/ejson/ejson.js:595:22)
W20181207-16:21:21.567(1)? (STDERR) (node:28726) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
OK, now using object shorthand instead of fat arrow syntax. If the credentials are bad I get the expected error. If the credentials are good, I get the pesky loop.
There’s nothing obvious from the code you’ve shared which would explain that behaviour.
Perhaps start by introducing some logging to isolate where the loop is being executed: for example, is the client calling the server repeatedly (the method is being re-run)?
I just looked at the docs for bind, and the res parameter is not documented, so I suspect it’s just returning client, which may well contain circular references.
As res is not returned, change the code (as I guess you’ve done) to this:
Yeah you can’t return circular structures from a method because it needs to be parsed into EJSON.
Sadly the stringifier for ejson doesn’t tell you when you’re parsing a circular structure, unlike JSON.stringify