rynop / dynamodb-local

A wrapper for AWS DynamoDB Local, intended for use in testcases
MIT License
51 stars 30 forks source link

Check if dynamodb-local tar file extraction is **completely** finished before resolving Promise #50

Open TysonAndre-tmg opened 8 months ago

TysonAndre-tmg commented 8 months ago

Problem: dynamodb-local may fail to download the dependencies of the jar (in DynamoDBLocal_lib) or the Node.js process may exit before the jar download is finished (or the https download may fail before it finishes), e.g. if there is a unit test timeout and the process exits before everything finish.

The fact that this is using pipe() to reduce memory usage (instead of waiting for the full download) makes it more likely that a folder will be created with incompletely extracted contents, though the bug could happen even without pipe (e.g. slow disk writes)

On slow internet connections or when a computer is under high load, this error can be more frequent.

Proposed solution

  1. Create a unique stub file with an arbitrary unique name such as dynamodb-local-downloaded-successfully.txt before calling deferred.resolve() on success
  2. Check that both the jar file and dynamodb-local-downloaded-successfully.txt exist before returning early.

(The first time libraries/applications using dynamodb-local update to a library version with this, they'll redownload dynamodb-local, but that should be fine)

Relevant parts of the code

  1. https://github.com/rynop/dynamodb-local/blob/b180b196e739149122d36ea7353a7d6556762375/index.js#L134
  2. https://github.com/rynop/dynamodb-local/blob/b180b196e739149122d36ea7353a7d6556762375/index.js#L167-L172

Related to #38 and #30