I’ve been reading excellent blog post by Rob Fallows: https://blog.meteor.com/using-promises-and-async-await-in-meteor-8f6f4a04f998
So i decided to switch our LDAP connection from wrapAsync to async/await syntax.
Looks like everything is working fine, except for callback invocation on a client.
Here is server code:
const LdapClient = Npm.require('promised-ldap')
Meteor.methods({
'ldap.testAsyncConnection': async function(server, port, login, pass) {
try {
const url = `ldap://${server}:${port}`
console.log('[methods.ldap.testAsyncConnection] creating client')
const client = new LdapClient({ url })
const dn = `cn=${login}`
console.log('[methods.ldap.testAsyncConnection] binding')
await client.bind(dn, pass)
console.log('[methods.ldap.testAsyncConnection] binded')
const searchOptions = {
attributes: ['dn', 'sn', 'cn']
}
console.log('[methods.ldap.testAsyncConnection] going to search')
const results = await client.search('<SEARCH HERE>', searchOptions)
console.log('[methods.ldap.testAsyncConnection] here are search results! ', results)
return {search: results}
} catch (e) {
console.warn('[methods.ldap.testAsyncConnection] exception, e = ', e)
return { success: false, error: e }
}
console.log('[methods.ldap.testAsyncConnection] after try/catch')
}
})
Here is client-side method invokation:
Meteor.call('ldap.testAsyncConnection', 'localhost', '6389', '<DN here>', '<pass here>', (err, res) => console.log(err, res))
Here is server log for that call:
I20170329-15:02:35.752(3)? [methods.ldap.testAsyncConnection] creating client
I20170329-15:02:35.757(3)? [methods.ldap.testAsyncConnection] binding
I20170329-15:02:35.765(3)? [methods.ldap.testAsyncConnection] binded
I20170329-15:02:35.765(3)? [methods.ldap.testAsyncConnection] going to search
I20170329-15:02:35.765(3)? [methods.ldap.testAsyncConnection] here are search results! { entries:
I20170329-15:02:35.767(3)? [ SearchEntry {
I20170329-15:02:35.768(3)? messageID: 2,
I20170329-15:02:35.768(3)? protocolOp: 100,
I20170329-15:02:35.771(3)? controls: [],
I20170329-15:02:35.771(3)? log: [Object],
I20170329-15:02:35.771(3)? objectName: '<NAME HERE>',
I20170329-15:02:35.788(3)? attributes: [],
I20170329-15:02:35.789(3)? connection: [Object] } ],
I20170329-15:02:35.789(3)? references: [] }
So everything is working great, but the client callback is never run. And after server restarts method invocations run again (i see it in server logs). What am i doing wrong?