Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob Storage conditional header(s) is not met #314

Closed
luspac opened this issue Aug 1, 2018 · 9 comments
Closed

Blob Storage conditional header(s) is not met #314

luspac opened this issue Aug 1, 2018 · 9 comments
Assignees
Labels
bug Indicates an unexpected problem or an unintended behavior.
Milestone

Comments

@luspac
Copy link

luspac commented Aug 1, 2018

I am having an issue with Blob Storage.

I am able to read and write information to Blob Storage but receive a warning:
Unhandled promise rejection (rejection id: 1): StorageError: The condition specified using HTTP conditional header(s) is not met.

To access the Blob Storage I pass in my settings.

const {BlobStorage} = require('botbuilder-azure');

var storage = new BlobStorage({
    containerName: '<container name>',
    storageAccountOrConnectionString: '<account or connection string>',
    host: '<host>'
});

The definition of BlobStorage requires a storageAccessKey but I immediately get thrown an error if I add that parameter to the Blob Storage connection.

The way in which I am accessing the storage is handled in this function below. Any insight into this would be much appreciated.

async function logMessageText(storage, context) {
    let utterance = context.activity.text;
    let storeItems = await storage.read(["UtteranceLog"])
    console.log(storeItems);
    try {
        // check result
        var utteranceLog = storeItems["UtteranceLog"];

        if (typeof (utteranceLog) != 'undefined') {
            // log exists so we can write to it
            storeItems["UtteranceLog"].UtteranceList.push(utterance);

            try {
                await storage.write(storeItems)
                context.sendActivity('Successful write to utterance log.');
            } catch (err) {
                context.sendActivity(`Write failed of UtteranceLog: ${err}`);
            }

        } else {
            context.sendActivity(`need to create new utterance log`);
            storeItems["UtteranceLog"] = { UtteranceList: [`${utterance}`]}

            try {
                await storage.write(storeItems)
                context.sendActivity('Successful write to log.');
            } catch (err) {
                context.sendActivity(`Write failed: ${err}`);
            }
        }
    } catch (err) {
        context.sendActivity(`Read rejected. ${err}`);
    };
}
@xtellurian
Copy link

xtellurian commented Aug 2, 2018

I'm seeing the same issue.

Code looks something like this:

import { BotFrameworkAdapter, MemoryStorage, ConversationState } from 'botbuilder';
import * as restify from 'restify';
import { BlobStorage } from 'botbuilder-azure';

const adapter = new BotFrameworkAdapter({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

var container_name = process.env.BLOB_CONTAINER; // container name
var storageAccountName = process.env.STORAGE_ACCOUNT_NAME; // single string, eg, 'test'
var storageAccountKey = process.env.STORAGE_ACCOUNT_KEY; //base64 encoded key
storage = new BlobStorage({ storageAccountOrConnectionString: storageAccountName, containerName: container_name, storageAccessKey: storageAccountKey });

const conversationState = new ConversationState<EchoState>(storage);
adapter.use(conversationState);

The error message looks like this

BotFrameworkAdapter.processActivity(): 500 ERROR - StorageError: The condition specified using HTTP conditional header(s) is not met.
RequestId:ca43a90b-a01e-001b-1a26-2ac0c5000000
Time:2018-08-02T06:04:46.3108046Z
(node:22380) UnhandledPromiseRejectionWarning: StorageError: The condition specified using HTTP conditional header(s) is not met.
RequestId:ca43a90b-a01e-001b-1a26-2ac0c5000000
Time:2018-08-02T06:04:46.3108046Z
    at Function.StorageServiceClient._normalizeError (C:\src\xtellurian\help\bot\src\halp\node_modules\azure-storage\lib\common\services\storageserviceclient.js:1198:23)
    at Object.StorageServiceClient._processResponse (C:\src\xtellurian\help\bot\src\halp\node_modules\azure-storage\lib\common\services\storageserviceclient.js:744:50)
    at Request.processResponseCallback [as _callback] (C:\src\xtellurian\help\bot\src\halp\node_modules\azure-storage\lib\common\services\storageserviceclient.js:317:37)

Authentication is correct - the container was created.

No blobs are created.

Package info:
-- botbuilder-azure@4.0.0-preview1.2
-- azure-storage@2.10.0

-- botbuilder@4.0.0-preview1.2

@szul
Copy link

szul commented Aug 2, 2018

Same here. After running into issue #277, I decided to switch to blob storage, and am now running into this.

@vishwacsena vishwacsena added this to the Release milestone Aug 8, 2018
@yochay yochay added bug Indicates an unexpected problem or an unintended behavior. Approved labels Aug 13, 2018
@yochay
Copy link
Contributor

yochay commented Aug 20, 2018

@stevengum will update storage packages

@stevengum
Copy link
Member

Currently investigating...

@stevengum
Copy link
Member

@luspac, @szul, @xtellurian, can you check your blob containers and see if there are any blobs being created? I think I found the actual issue (or another issue).

@szul
Copy link

szul commented Aug 23, 2018

@stevengum In my case, no blobs were actually created in the blob containers.

Something to note: With both this and table storage, something like @xtellurian's code is what throws the error for me; however, if I take that same blob storage or table storage object that has been initialized, and try to read/write to it, I can do so successfully. The error seems to be exclusively with state management.

@stevengum
Copy link
Member

@szul, what you said confirms what I suspected; the blob isn't created and a 404 is actually thrown at some point(s).

(Also, on rereading @xtellurian's comment confirms the same)

This is because we're trying to get a blob that doesn't exist (the code currently creates a container if the container is not found, but there aren't any doesBlobExist checks). I modified the code in JS to do a blob check before trying to retrieve the blob, and also had it create a blob if the blob doesn't already exist. After these changes, the bot worked fine with no errors thrown.

I believe the 412 (The condition specified using HTTP conditional header(s) is not met) is thrown when the bot tries to write changes.

I'm working today to get this bug fixed and if all goes well it should be out in our nightly builds tonight, which can be found here.

@stevengum
Copy link
Member

#369 is currently on hold while we wait for @Stevenic to weigh in.

@sgellock
Copy link
Member

fix merged into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or an unintended behavior.
Projects
None yet
Development

No branches or pull requests

7 participants