I started with a bog standard cosmos query example in C#.
When the code hits this line, it exits with no further information:
var currentResultSet = await queryResultSetIterator.ReadNextAsync();
To verify something was working, I created this snippet:
this.cosmosClient = new CosmosClient(EndpointUri, PrimaryKey);
this.container = cosmosClient.GetContainer(databaseId, containerId);
// This code worked and I verified results in data explorer
var deltest = this.cosmosClient.GetContainer(databaseId, "deleteme");
deltest.DeleteContainerAsync().Wait();
// this exits immediately, no exception
var a = await this.container.ReadContainerAsync();
The ReadContainerAsync left an important clue I did not see in the query code:
DocDBTrace Information: 0 : Azure Environment metadata information not available. A socket operation was attempted to an unreachable network. (169.254.169.254:80)
I have looked through the container setup, and I don't see anything. Is there an option I need to enable to allow the container to be queryable?
EDIT 1
After playing with this for a bit. I am encountering behavior I would not normally expect to see. A bit of boring background:
- I am doing TDD with a unit test project for a .NET 6 library
- I am testing a class implementing an interface that hides the DB from the caller
- Class has a constructor and a single async method
This TEST code in the constructor works:
var deltest = this.cosmosClient.GetContainer(databaseId, "deletetesttwo");
deltest.DeleteContainerAsync().Wait();
This TEST code in the async method exits the unit test project debug mode instantly:
var deltest = this.cosmosClient.GetContainer(databaseId, "deletetesttwo");
await deltest.DeleteContainerAsync();
I am recreating containers using data explorer between invocations.
CodePudding user response:
FACEPALM
After looking at this: Cosmos DB call never returns with async call
Remember kids: A unit test project example test method isn't async when you first create the class.
Changing the test method to async and adding await fixed the issue.