forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core-amqp] adds support for idle timeout and additional logging (#6492)
* [core-amqp] adds logging around dns.resolve in checkNetworkConnection * [core-amqp] adds support for idle timeout check * updates pnpm lock file
- Loading branch information
Showing
11 changed files
with
392 additions
and
330 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
sdk/core/core-amqp/src/util/checkNetworkConnection.browser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* Checks whether a network connection is detected. | ||
* @ignore | ||
* @internal | ||
*/ | ||
export function checkNetworkConnection(): Promise<boolean> { | ||
return Promise.resolve(window.navigator.onLine); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { resolve, CONNREFUSED, TIMEOUT } from "dns"; | ||
import { retry as logRetry } from "../log"; | ||
|
||
/** | ||
* Checks whether a network connection is detected. | ||
* @ignore | ||
* @internal | ||
*/ | ||
export function checkNetworkConnection(host: string): Promise<boolean> { | ||
return new Promise((res) => { | ||
logRetry("Calling dns.resolve to determine network connection status."); | ||
resolve(host, function(err: any): void { | ||
if (err) { | ||
logRetry( | ||
"Error thrown from dns.resolve in network connection check: '%s', %O", | ||
err.code || err.name, | ||
err | ||
); | ||
// List of possible DNS error codes: https://nodejs.org/dist/latest-v12.x/docs/api/dns.html#dns_error_codes | ||
// Only when dns.resolve returns an error we expect to see when the network is down, resolve as 'false'. | ||
if (err.code === CONNREFUSED || err.code === TIMEOUT) { | ||
return res(false); | ||
} | ||
} else { | ||
logRetry("Successfully resolved host via dns.resolve in network connection check."); | ||
} | ||
|
||
return res(true); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters