Sunday 10 March 2019

Cosmos DB emulator returns wrong IP address

I configured the Cosmos DB emulator to listen across the network. It was running on a developer laptop that had Docker for Windows installed.

Connecting from a different Linux laptop using Gateway mode, I was getting long delays and then "a task was cancelled". This was coming from deep within the HTTP stack.

On closer inspection I could see that the client was trying to connect to https://10.0.75.1 - this is the Docker network.

In the GetDatabaseAccountAsync method the client connects to the gateway and enumerates the databases:

https://cosmosdb.test:8081/

The gateway returns a JSON response. This can be seen in Visual Studio Code with the following debug query:

System.Text.Encoding.ASCII.GetString(((System.IO.MemoryStream)documentServiceResponse.ResponseBody).ToArray())

The databaseAccountEndpoint property returns https://10.0.75.1:8081 and this is used to form subsequent responses.
{
    "_self": "",
    "id": "localhost",
    "_rid": "cosmosdb.test",
    "media": "//media/",
    "addresses": "//addresses/",
    "_dbs": "//dbs/",
    "writableLocations": [
        {
            "name": "South Central US",
            "databaseAccountEndpoint": "https://10.0.75.1:8081/"
        }
    ],
    "readableLocations": [
        {
            "name": "South Central US",
            "databaseAccountEndpoint": "https://10.0.75.1:8081/"
        }
    ],
    "enableMultipleWriteLocations": false,
    "userReplicationPolicy": {
        "asyncReplication": false,
        "minReplicaSetSize": 1,
        "maxReplicasetSize": 4
    },
    "userConsistencyPolicy": {
        "defaultConsistencyLevel": "Session"
    },
    "systemReplicationPolicy": {
        "minReplicaSetSize": 1,
        "maxReplicasetSize": 4
    },
    "readPolicy": {
        "primaryReadCoefficient": 1,
        "secondaryReadCoefficient": 1
    },
    "queryEngineConfiguration": "{\\"maxSqlQueryInputLength\\":262144,\\"maxJoinsPerSqlQuery\\":5,\\"maxLogicalAndPerSqlQuery\\":500,\\"maxLogicalOrPerSqlQuery\\":500,\\"maxUdfRefPerSqlQuery\\":10,\\"maxInExpressionItemsCount\\":16000,\\"queryMaxInMemorySortDocumentCount\\":500,\\"maxQueryRequestTimeoutFraction\\":0.9,\\"sqlAllowNonFiniteNumbers\\":false,\\"sqlAllowAggregateFunctions\\":true,\\"sqlAllowSubQuery\\":true,\\"sqlAllowScalarSubQuery\\":true,\\"allowNewKeywords\\":true,\\"sqlAllowLike\\":false,\\"sqlAllowGroupByClause\\":false,\\"maxSpatialQueryCells\\":12,\\"spatialMaxGeometryPointCount\\":256,\\"sqlAllowTop\\":true,\\"enableSpatialIndexing\\":true}"
}

No comments:

Post a Comment