Skip to content

[BIGTABLE] Insert callback called multiple times if err #1846

@harscoet

Description

@harscoet

Environment details

  • OS: macOS Sierra 10.12.11
  • Node.js version: 6.9.1
  • npm version: 3.10.8
  • google-cloud-node version: "@google-cloud/bigtable": "^0.6.0"

Steps to reproduce

I use "insert" function to insert an array of 2 entries, for the example I force error with "wrong" timestamp (yes timestamp defined in milliseconds is invalid...)

let i = 0;
const INSTANCE_NAME = 'myInstance';

require('@google-cloud/bigtable')().instance(INSTANCE_NAME).table('test').insert([{
  key: 'alincoln',
  data: {
    follows: {
      gwashington: {
        value: 1,
        timestamp: 1480517318949 // Invalid timestamp (note 1480517318 in seconds is OK, 1480517318949000 in microseconds is OK)
      }
    }
  }
},{
  key: 'alincoln',
  data: {
    follows: {
      helloworld: {
        value: 1,
        timestamp: 1480517318949 // Invalid timestamp (note 1480517318 in seconds is OK, 1480517318949000 in microseconds is OK)
      }
    }
  }
}], err => {
  i++;
  console.log('--');
  console.log(`CALLBACK ${i}`);
  if (err) console.error(err.message);
  console.log('--');
});

/*
--
CALLBACK 1
--
--
CALLBACK 2
Error in field 'entries' : Error in element #0 : Error in field 'Mutation list' : Error in element #0 : Timestamp granularity mismatch. Expected a multiple of 1000 (millisecond granularity), but got 1480517318949.
--
*/

In source file "table.js" I just add some logs to find source of error, callback is called multiple times, first time with end event, and last with error event
If I use promise syntax I just never see that an error occurred because promise is resolved with end event without error

// table.js - line 868
this.requestStream(grpcOpts, reqOpts)
  .on('error', (err) => {
    console.log('event:error', err); // LAST_LOG: event:error { Error: Error in field 'entries' : Error in element #0 : Error in field 'Mutation list' : Error in element #0 : Timestamp granularity mismatch. Expected a multiple of 1000 (millisecond granularity), but got 1480517318949.
    callback(err);
  })
  .on('data', function (obj) {
    obj.entries.forEach(function (entry) {
      // Mutation was successful.
      if (entry.status.code === 0) {
        return;
      }

      var status = common.GrpcService.decorateStatus_(entry.status);
      status.entry = entries[entry.index];

      mutationErrors.push(status);
    });
  })
  .on('end', function () {
    var err = null;

    if (mutationErrors.length > 0) {
      err = new common.util.PartialFailureError({
        errors: mutationErrors
      });
    }

    console.log('event:end', err); // FIRST_LOG: event:end null
    callback(err);
  });

Metadata

Metadata

Assignees

Labels

api: bigtableIssues related to the Bigtable API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions