andrewrk / node-s3-client

high level amazon s3 client for node.js
MIT License
1k stars 303 forks source link

Node crashing when syncing directory #199

Open jashaffe opened 6 years ago

jashaffe commented 6 years ago

There is actually two issues. The first is that node is crashing when trying to sync directories. Here is the error:

node[3016]: ../src/tls_wrap.cc:621:virtual int node::TLSWrap::DoWrite(node::WriteWrap*, uv_buf_t*, size_t, uv_stream_t*): Assertion `(current_write_) == (nullptr)' failed.
 1: node::Abort() [node]
 2: 0x8c811b [node]
 3: 0x999b4e [node]
 4: node::StreamBase::WriteBuffer(v8::FunctionCallbackInfo<v8::Value> const&) [node]
 5: void node::StreamBase::JSMethod<node::TLSWrap, &node::StreamBase::WriteBuffer>(v8::FunctionCallbackInfo<v8::Value> const&) [node]
 6: 0x1e5c206b8b07
Aborted

Here is the script:

let s3 = require('s3');

//Format HttpUploadProgress Size
function formatBytes(a, b) {
    if (0 == a) return "0 Bytes";
    let c = 1024,
        d = b || 2,
        e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
        f = Math.floor(Math.log(a) / Math.log(c));
    return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f];
}

let client = s3.createClient({
  s3RetryCount: 3,    // this is the default
  s3RetryDelay: 1000, // this is the default
  multipartUploadSize: 5242880, // this is the default (15 MB)
  s3Options: {
    accessKeyId: "blahblah",
    secretAccessKey: "blahblah",
    region:"us-gov-west-1"
  },
});

let params = {
  localDir: "/home/ec2-user/sync/",
  deleteRemoved: true, // default false, whether to remove s3 objects
                       // that have no corresponding local file.

  s3Params: {
    Bucket: "ami-bucket-govcloud",
    // other options supported by putObject, except Body and ContentLength.
    // See: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property
  },
};
let uploader = client.uploadDir(params);
uploader.on('error', function(err) {
  console.error("unable to sync:", err.stack);
});
uploader.on('progress', function() {
  console.log("progress", formatBytes(uploader.progressAmount), formatBytes(uploader.progressTotal));
});
uploader.on('end', function() {
  console.log("done uploading");
});

The second which may be causing the issue, is the multipart sizes are not responding to configuration:

progress 400.13 MB 1 GB
progress 400.14 MB 1 GB
progress 400.16 MB 1 GB
progress 400.17 MB 1 GB
progress 400.19 MB 1 GB
progress 400.2 MB 1 GB
progress 400.22 MB 1 GB
progress 400.23 MB 1 GB
progress 400.25 MB 1 GB
progress 400.27 MB 1 GB
progress 400.28 MB 1 GB
progress 400.3 MB 1 GB
progress 400.31 MB 1 GB
progress 400.33 MB 1 GB
progress 400.34 MB 1 GB