question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SDK not respecting default account consistency

See original GitHub issue

Summary:

Creating an item using the create() method and then immediately retrieving it using an SQL statement works 90% of the times. But in the other 10%, the query doesn’t return the item - even though it was indeed created.

Steps to reproduce:

For full details & the code, see: Article Code sample Note: these don’t mention the error, as they are part of materials I created for a University course I’m teaching.

The relevant code snippet:

`const newItemId = Math.floor(Math.random() * 1000 + 10).toString();
let documentDefinition = { “id”: newItemId, “name”: “Angus MacGyver”, “state”: “Building stuff” };

// Add a new item to the container const createResponse = await container.items.create(documentDefinition); console.log(createResponse.body);

// Execute SQL query to retrieve the new item const querySpec = { query: “SELECT * FROM c WHERE c.id=@id”, parameters: [ { name: “@id”, value: newItemId } ] }; const queryResponse = await container.items.query(querySpec).toArray(); console.log(queryResponse.result[0].name);`

In most cases, the SQL query returns the item. From time to time, the item isn’t returned, though. However, looking at the Azure Data Explorer, it was indeed created. The response of the Cosmos DB doesn’t indicate any error:

{ result: [], headers: { 'cache-control': 'no-store, no-cache', pragma: 'no-cache', 'transfer-encoding': 'chunked', 'content-type': 'application/json', server: 'Microsoft-HTTPAPI/2.0', 'strict-transport-security': 'max-age=31536000', 'x-ms-last-state-change-utc': 'Thu, 11 Oct 2018 01:27:52.965 GMT', 'x-ms-resource-quota': 'documentSize=10240;documentsSize=10485760;documentsCount=-1;collectionSize=10485760;', 'x-ms-resource-usage': 'documentSize=0;documentsSize=0;documentsCount=14;collectionSize=0;', lsn: '145', 'x-ms-item-count': '0', 'x-ms-schemaversion': '1.6', 'x-ms-alt-content-path': 'dbs/ToDoList/colls/Items', 'x-ms-content-path': 'fvlLALM+HAA=', 'x-ms-xp-role': '2', 'x-ms-global-committed-lsn': '145', 'x-ms-number-of-read-regions': '1', 'x-ms-transport-request-id': '150741', 'x-ms-cosmos-llsn': '145', 'x-ms-session-token': '0:-1#145', 'x-ms-request-charge': '1.97', 'x-ms-serviceversion': 'version=2.1.0.0', 'x-ms-activity-id': '2b20d905-3801-4248-9852-95ebcca08d08', 'x-ms-gatewayversion': 'version=2.1.0.0', date: 'Thu, 11 Oct 2018 13:01:22 GMT', 'x-ms-throttle-retry-count': 0, 'x-ms-throttle-retry-wait-time-ms': 0 } }

Now, I suspect the error could be related to some throughput / throttling issue. However, it’s then strange that the code works most of the time and fails at random intervals, without the API informing me about an issue. Also, if the JavaScript API to create the item returns with success and all the item details (including _rid, _self, …), I’d expect the item to be retrievable.

Searched the documentation for any hints or best practices, but didn’t find any. Inserting a sleep statement into the Node.js code isn’t really a great work-around either.

Therefore, reporting this as a potential issue, as the API returns that the item was created, but it’s not (yet).

Environment

Cosmos DB JS library version: 2.0.2 Node.js version: 8.12.0 (latest LTS)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
southpolestevecommented, Oct 15, 2018

@andijakl I’m able to replicate this bug. We’re not respecting the default account consistency setting in the SDK. The workaround is to set the consistency explicitly as you did above. We’ll look into a fix. I changed the title to reflect the underlying issue.

0reactions
github-actions[bot]commented, Aug 23, 2019

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

Read more comments on GitHub >

github_iconTop Results From Across the Web

Consistency levels in Azure Cosmos DB
Azure Cosmos DB has five consistency levels to help balance eventual consistency, availability, and latency trade-offs.
Read more >
Initializing the gcloud CLI | Google Cloud CLI Documentation
gcloud init performs the following setup steps: Authorizes the gcloud CLI to use your user account credentials to access Google Cloud, or lets...
Read more >
Configure consistency models in the portal and the Azure ...
The default consistency level for new Azure Cosmos DB for NoSQL accounts is session consistency. This default setting can be modified for all...
Read more >
Read consistency - Amazon DynamoDB
When you request a strongly consistent read, DynamoDB returns a response with the most up-to-date data, reflecting the updates from all prior write...
Read more >
Users API
When Optional Password is enabled, the user status following user creation can be affected by the enrollment ... Create User with non-default User...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found