azure-sdk-for-js: Cosmos DB Node JS client fails to connect when working behind corporate proxy
- Package Name: azure/cosmos
- Package Version: 2.1.7
- Operating system: Windows
- nodejs
- version: v8.9.4 (and up)
- browser
- name/version: any
- typescript
- version: N\A
- Is the bug related to documentation in
- README.md
- source code documentation
- SDK API docs on https://docs.microsoft.com
Describe the bug When trying to connect to Cosmos DB from a computer behind corporate proxy, the connection fails. The error happens only from Cosmos DB NodeJS client. Using Cosmos DB Python client works as expected. The error itself happens internally inside the Node JS client code, and is caught inside without any response to the calling code.
The specific error is (can be seen only via debugging the client code): “Error: tunneling socket could not be established, cause=socket hang up”
It appears that the code inside Cosmos DB NodeJS client (the function createRequestObject, inside request.ts) does not use the proxy configuration passed to it in the connection policy object. This is the root cause of the problem.
I’m adding here 2 code snippets, the Node JS (not working) client and the Python (working) client
Node JS client code (not working)
let connectionPolicy = { ProxyUrl: 'https://<proxy>:8080', RequestTimeout: 1000 , DisableSSLVerification : true }; const cosmosClient = new CosmosClient({ endpoint: "https://<target-cosmosdb>:443/", auth: { masterKey: "<master-key-value>}, connectionPolicy : connectionPolicy}); const { resource: databaseDefinition } = await this.client.database("<db-name>").read();
Python client code (working) import azure.cosmos.cosmos_client as CosmosClient import azure.cosmos.documents as documents connection_policy = documents.ConnectionPolicy() connection_policy.DisableSSLVerification = True connection_policy.RequestTimeout = 1000 connection_policy.ProxyConfiguration = documents.ProxyConfiguration() connection_policy.ProxyConfiguration.Host = ‘https://proxy’ connection_policy.ProxyConfiguration.Port = 8080 client = CosmosClient.CosmosClient(‘https://<target-cosmosdb>:443/’, { ‘masterKey’ : ‘<master-key-value>’}, connection_policy)
database_link = ‘dbs/<db-name>’ database = client.ReadDatabase(database_link)
To Reproduce Steps to reproduce the behavior:
- Create a Node JS Cosmos DB client according to the code snippet above
- Run the code when behind a corporate proxy
Expected behavior Connection should be opened successfully and the requested database should be read
Screenshots N\A
Additional context N\A
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (5 by maintainers)
Thanks for working with Microsoft on GitHub! Tell us how you feel about your experience using the reactions on this comment.