IBM / ibm-cos-sdk-js

ibm-cos-sdk-js
Apache License 2.0
38 stars 19 forks source link

COS-interacting script never exits #28

Closed pzbitskiy closed 6 years ago

pzbitskiy commented 6 years ago

Hello,

I run the following code and the script never finishes (does not return back to shell):

const AWS = require('ibm-cos-sdk');
const config = {
    apiKeyId: creds.apikey,
    endpoint: "https://s3.us-south.objectstorage.softlayer.net",
    serviceInstanceId: creds.resource_instance_id
};

let cos = new AWS.S3(config);

function doCreateBucket() {
    console.log('Creating bucket');
    return cos.createBucket({
        Bucket: 'my-bucket-unique-name-112233',
        CreateBucketConfiguration: {
            LocationConstraint: 'us-south'
          },
    }).promise();
}

doCreateBucket().then(
    () => console.log("done")
);

Console output:

[username@localhost bluemix]$ node cos.js 
Creating bucket
done

^C
[username@localhost bluemix]$ node -v
v8.11.3

So... What's wrong with it?

paul-carron commented 6 years ago

This only happens with IAM auth. With hmac, the promise finishes correctly. I'm looking into the cause of this.

ScottChapman commented 6 years ago

I am seeing this too...

widget- commented 6 years ago

Looks like it's the preemptive IAM token refresh code: https://github.com/IBM/ibm-cos-sdk-js/blob/master/lib/iam/token_manager.js#L381

widget- commented 6 years ago

We're looking into some fixes. For now it looks like the workaround is to call process.exit() after the final call.

e.g.:

// es5
doCreateBucket()
    .then((res) => console.log('Response: ' + util.inspect(res)))
    .catch((err) => console.log('An exception occurred: ' + util.inspect(err)))
    .then(() => process.exit(0));

or

// es6
try {
    const res = await doCreateBucket();
    console.log(`Response: ${res}`);
} catch (err) {
    console.log(`An exception occurred: ${err}`);
}
console.log('done');
process.exit(0);
akosbalasko commented 6 years ago

Same story here...

paul-carron commented 6 years ago

This is resolved in release 1.3.1.