Google-api-nodejs-client: "Resource Not Found: groupKey" randomly appears

Created on 2 Apr 2014  路  12Comments  路  Source: googleapis/google-api-nodejs-client

I have a script that:

  1. Creates a new group
  2. Adds a member to that group
  3. Removes the member from that group
  4. Deletes the group
  5. Continue with step 1

The code is:

// Authentication via JWT
...
var testGroup = "[email protected]"
  , emailToAdd = "[email protected]"
  , k = 0
  ;

(function foo () {

    console.log("-------- TEST " + (++k) + " --------------");
    // group insert
    client.admin.groups.insert({
        email: testGroup
    }).execute(function (err, data) {

        console.log("Group create: ", err || data);
        // member insert
        client.admin.members.insert({
            groupKey: testGroup
        }, {
            email: emailToAdd
        }).execute(function (err, data) {

            console.log("Member insert", err || data);

            // member delete
            client.admin.members.delete({
                groupKey: testGroup
              , memberKey: emailToAdd
            }).execute(function (err, data) {
                console.log("Member remove", err || data);

                // group delete
                client.admin.groups.delete({
                    groupKey: testGroup
                }).execute(function (err, data) {
                    console.log("Group remove", err || data);
                    foo();
                });
            });
        });
    });
})()
...

Sometimes the Resource Not Found: groupKey error appears. I suppose that the group is not yet created and the member add request is run. How can I solve this?

The output of the script is:

-------- TEST 1 --------------
Group create:  { errors: 
   [ { domain: 'global',
       reason: 'duplicate',
       message: 'Entity already exists.' } ],
  code: 409,
  message: 'Entity already exists.' }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined
-------- TEST 2 --------------
Group create:  { kind: 'admin#directory#group',
  id: '03o7alnk441n1np',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/JKrfOps9z8-vupenUPMMdOhJKPg"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined
-------- TEST 3 --------------
Group create:  { kind: 'admin#directory#group',
  id: '0279ka653b9rvvn',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/YBgVLGVcZ6tdkPuc-5IUkE8X05o"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined
-------- TEST 4 --------------
Group create:  { kind: 'admin#directory#group',
  id: '03tbugp118bejev',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/Siz_CPzNREhf4MGin9AJq_VZrLc"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
Member remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: memberKey' } ],
  code: 404,
  message: 'Resource Not Found: memberKey' }
Group remove undefined
-------- TEST 5 --------------
Group create:  { kind: 'admin#directory#group',
  id: '048pi1tg3gm9un2',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/r5nsQPCQmcwk9lUQOZ2GTNiXZPE"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined
-------- TEST 6 --------------
Group create:  { kind: 'admin#directory#group',
  id: '02lwamvv11s6mg1',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/eAl4dE-UPwdVkzy8BqRXlXdR0YQ"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined
-------- TEST 7 --------------
Group create:  { kind: 'admin#directory#group',
  id: '0184mhaj48dzd5k',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/oylcdbftOAkzLCZpKByy242ilIM"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
Member remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: memberKey' } ],
  code: 404,
  message: 'Resource Not Found: memberKey' }
Group remove undefined
-------- TEST 8 --------------
Group create:  { kind: 'admin#directory#group',
  id: '01ljsd9k1af4qm1',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/yJ3gt__XCVUhb8u86UAyo3u4czg"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
Member remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: memberKey' } ],
  code: 404,
  message: 'Resource Not Found: memberKey' }
Group remove undefined
-------- TEST 9 --------------
Group create:  { kind: 'admin#directory#group',
  id: '00gjdgxs2los8l8',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/4T5RsXeuCvgAstmfn0_qFuDjqVg"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
Member remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: memberKey' } ],
  code: 404,
  message: 'Resource Not Found: memberKey' }
Group remove undefined
-------- TEST 10 --------------
Group create:  { kind: 'admin#directory#group',
  id: '02w5ecyt4altqa7',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/wag6MJmfhnNhHEVk56qrBcepm3g"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined
-------- TEST 11 --------------
Group create:  { kind: 'admin#directory#group',
  id: '030j0zll0gjf6ad',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/TZAhihNRAdg22j3Q0v_vcBgOEqY"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
Member remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: memberKey' } ],
  code: 404,
  message: 'Resource Not Found: memberKey' }
Group remove undefined
-------- TEST 12 --------------
Group create:  { kind: 'admin#directory#group',
  id: '039kk8xu1xc7orv',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/8cz7c02KSGvLf4STOsyf2ECj53A"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined
-------- TEST 13 --------------
Group create:  { kind: 'admin#directory#group',
  id: '0206ipza46ltn2o',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/X0mKZCQggXKKo2g47QCfe8MqbFA"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
Member remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: memberKey' } ],
  code: 404,
  message: 'Resource Not Found: memberKey' }
Group remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
-------- TEST 14 --------------
Group create:  { errors: 
   [ { domain: 'global',
       reason: 'duplicate',
       message: 'Entity already exists.' } ],
  code: 409,
  message: 'Entity already exists.' }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined
-------- TEST 15 --------------
Group create:  { kind: 'admin#directory#group',
  id: '02afmg282f4pg7v',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/5PTQNzkG_UZ4f4eO9b6IkosJ2VM"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined
-------- TEST 16 --------------
Group create:  { kind: 'admin#directory#group',
  id: '04h042r01wv6svp',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/aPbOI_qXAA_TqrAk2SbkqlWWWxQ"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
Group remove undefined
-------- TEST 17 --------------
Group create:  { kind: 'admin#directory#group',
  id: '01d96cc01cztl7q',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/rizaxgZ2v2PYLcdW5xiltVenpb0"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
Member remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: memberKey' } ],
  code: 404,
  message: 'Resource Not Found: memberKey' }
Group remove undefined
-------- TEST 18 --------------
Group create:  { kind: 'admin#directory#group',
  id: '03j2qqm339mfz41',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/C84QWOuIBW0GTXKzSfpPGZ3Z5JA"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { kind: 'admin#directory#member',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/88eFsAOwd57HlxafEY8Mz1oFMaE"',
  id: '109274325672508858588',
  email: '[email protected]',
  role: 'MEMBER',
  type: 'USER' }
Member remove undefined
Group remove undefined

@rakyll Any idea? Thanks!

triage me

Most helpful comment

@alfasin _WONTFIX_ or _That's the intended behavior_ are two fast ways to _fix_ bugs. :smile:

All 12 comments

Temporary fixed adding some timeouts, but it's not an elegant solution...

@rakyll Any progress on this?

This looks like a race condition that's happening at the API level, not at our client level. Specifically at TEST 4

-------- TEST 4 --------------
Group create:  { kind: 'admin#directory#group',
  id: '03tbugp118bejev',
  etag: '"KbzxxlrznavcDE7kirZiCFvGH0s/Siz_CPzNREhf4MGin9AJq_VZrLc"',
  email: '[email protected]',
  name: 'johnny-test',
  description: '',
  adminCreated: true }
Member insert { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: groupKey' } ],
  code: 404,
  message: 'Resource Not Found: groupKey' }
Member remove { errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Resource Not Found: memberKey' } ],
  code: 404,
  message: 'Resource Not Found: memberKey' }
Group remove undefined

Seems the group is created with the id groupKey, then member insertion fails because the API fails to see the new group. Member remove fails subsequently because it was never inserted in the first place, and then group deletion works because the API finally sees the new group.

This looks like a race condition that's happening at the API level, not at our client level.

Will devs fix this?

Bug filed internally. b/16196229

Thanks!

@IonicaBizau Wish I had a better response than this but they replied to the internal bug saying 'Won't Fix (Intended Behavior)' with a reason related to their architecture choice. Hopefully this issue will eventually resolve itself internally but for now I am closing this issue as it's technically unrelated to this API client.

Thanks for feedback. The workaround I found is to set some timeouts (~4000ms) to be _sure_ that the API did its job.

That's why I LOVE Google APIs: not only friendly error messages and great documentations - but they also fix their bugs very quickly. Go Google!

@alfasin _WONTFIX_ or _That's the intended behavior_ are two fast ways to _fix_ bugs. :smile:

@IonicaBizau that's also the fastest way to let your customers know you don't give a sh*t about them. It's very unfortunate that a company like Google shows this kind of unprofessional attitude...

Well, let's hope the time will fix it. :smile: Probably they try to keep the issues clean.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Chethandsagar picture Chethandsagar  路  4Comments

oliverjessner picture oliverjessner  路  3Comments

hainguyents13 picture hainguyents13  路  3Comments

streamnsight picture streamnsight  路  4Comments

rainabba picture rainabba  路  4Comments