message: Ensure no additional messages are processed after a critical context error occurs
diff: @@ -17,6 +17,7 @@ export class DocumentPartition extends EventEmitter {
  private lambda: IPartitionLambda;
  private corrupt = false;
  private activityTimer: NodeJS.Timeout | undefined;
  + private closed = false;
  constructor(
  factory: IPartitionLambdaFactory,
  @@ -57,6 +58,14 @@ export class DocumentPartition extends EventEmitter {
  1);
  this.q.pause();
  + this.context.on("error", (error: any, restart: boolean) => {
  + if (restart) {
  + // ensure no more messages are processed by this partition
  + // while the process is restarting / closing
  + this.close();
  + }
  + });
  +
  // Create the lambda to handle the document messages
  this.lambdaP = factory.create(documentConfig, context);
  this.lambdaP.then(
  @@ -71,11 +80,21 @@ export class DocumentPartition extends EventEmitter {
  }
  public process(message: IQueuedMessage) {
  + if (this.closed) {
  + return;
  + }
  +
  this.q.push(message);
  this.updateActivityTimer();
  }
  public close() {
  + if (this.closed) {
  + return;
  + }
  +
  + this.closed = true;
  +
  this.clearActivityTimer();
  this.removeAllListeners();
  @@ -83,6 +102,9 @@ export class DocumentPartition extends EventEmitter {
  // Stop any future processing
  this.q.kill();
  + if (this.lambda) {
  + this.lambda.close();
  + } else {
  this.lambdaP.then(
  (lambda) => {
  lambda.close();
  @@ -91,6 +113,7 @@ export class DocumentPartition extends EventEmitter {
  // Lambda was never created - ignoring
  });
  }
  + }
  private updateActivityTimer() {
  this.clearActivityTimer();
  