Skip to content

Commit 9b350d0

Browse files
committed
Move discovery timeout to Discover class
And use the timeout as the default Webfinger request timeout, too
1 parent 80c192b commit 9b350d0

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Diff for: src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const config = {
1717
// default config
1818
backgroundSyncInterval: 60000,
1919
disableFeatures: [],
20-
discoveryTimeout: 10000,
20+
discoveryTimeout: 5000,
2121
isBackground: false,
2222
requestTimeout: 30000,
2323
syncInterval: 10000

Diff for: src/discover.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import WebFinger from 'webfinger.js';
44
import type { StorageInfo } from './interfaces/storage_info';
5+
import config from './config';
56
import log from './log';
67
import { globalContext, localStorageAvailable } from './util';
78

@@ -19,9 +20,9 @@ let cachedInfo = {};
1920
* This function deals with the Webfinger lookup, discovering a connecting
2021
* user's storage details.
2122
*
22-
* @param {string} userAddress - user@host or URL
23+
* @param userAddress - user@host or URL
2324
*
24-
* @returns {Promise} A promise for an object with the following properties.
25+
* @returns A promise for an object with the following properties.
2526
* href - Storage base URL,
2627
* storageApi - RS protocol version,
2728
* authUrl - OAuth URL,
@@ -38,9 +39,13 @@ const Discover = function Discover(userAddress: string): Promise<StorageInfo> {
3839
const webFinger = new WebFinger({
3940
tls_only: false,
4041
uri_fallback: true,
41-
request_timeout: 5000
42+
request_timeout: config.discoveryTimeout
4243
});
4344

45+
setTimeout(() => {
46+
return reject(new Error('timed out'));
47+
}, config.discoveryTimeout);
48+
4449
return webFinger.lookup(userAddress, function (err, response) {
4550
if (err) {
4651
return reject(err);

0 commit comments

Comments
 (0)