Skip to content

Commit

Permalink
fix: remove client-side timeout from http rpc calls (#3178)
Browse files Browse the repository at this point in the history
Do not set up a client-side timeout, instead rely on the server-side version.

The global timeout is still respected, users can use an AbortSignal to do
timeouts on a per-call basis if desired.

Also brings refs API in line with go-IPFS - timeouts are recorded in the `.err`
prop of the output instead of the whole API call throwing a `TimeoutError`

fixes: #3161
  • Loading branch information
achingbrain authored Sep 1, 2021
1 parent 025914e commit 8a498fe
Show file tree
Hide file tree
Showing 96 changed files with 12 additions and 100 deletions.
1 change: 0 additions & 1 deletion src/add-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = configure((api) => {
...options,
progress: Boolean(progressFn)
}),
timeout: options.timeout,
onUploadProgress,
signal,
headers,
Expand Down
1 change: 0 additions & 1 deletion src/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = configure(api => {
async function stat (options = {}) {
const res = await api.post('bitswap/stat', {
searchParams: toUrlSearchParams(options),
timeout: options.timeout,
signal: options.signal,
headers: options.headers
})
Expand Down
1 change: 0 additions & 1 deletion src/bitswap/unwant.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function unwant (cid, options = {}) {
const res = await api.post('bitswap/unwant', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: cid.toString(),
Expand Down
1 change: 0 additions & 1 deletion src/bitswap/wantlist-for-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function wantlistForPeer (peerId, options = {}) {
const res = await (await api.post('bitswap/wantlist', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
...options,
Expand Down
1 change: 0 additions & 1 deletion src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function wantlist (options = {}) {
const res = await (await api.post('bitswap/wantlist', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options),
headers: options.headers
Expand Down
1 change: 0 additions & 1 deletion src/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function get (cid, options = {}) {
const res = await api.post('block/get', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: cid.toString(),
Expand Down
1 change: 0 additions & 1 deletion src/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = configure(api => {
let res
try {
const response = await api.post('block/put', {
timeout: options.timeout,
signal: signal,
searchParams: toUrlSearchParams(options),
...(
Expand Down
1 change: 0 additions & 1 deletion src/block/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = configure(api => {
}

const res = await api.post('block/rm', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: cid.map(cid => cid.toString()),
Expand Down
1 change: 0 additions & 1 deletion src/block/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function stat (cid, options = {}) {
const res = await api.post('block/stat', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: cid.toString(),
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function add (addr, options = {}) {
const res = await api.post('bootstrap/add', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: addr,
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function clear (options = {}) {
const res = await api.post('bootstrap/rm', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
...options,
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function list (options = {}) {
const res = await api.post('bootstrap/list', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options),
headers: options.headers
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function reset (options = {}) {
const res = await api.post('bootstrap/add', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
...options,
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function rm (addr, options = {}) {
const res = await api.post('bootstrap/rm', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: addr,
Expand Down
1 change: 0 additions & 1 deletion src/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function * cat (path, options = {}) {
const res = await api.post('cat', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path.toString(),
Expand Down
1 change: 0 additions & 1 deletion src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
const commands = async (options = {}) => {
const res = await api.post('commands', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options),
headers: options.headers
Expand Down
1 change: 0 additions & 1 deletion src/config/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = configure(api => {
}

const res = await api.post('config', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: key,
Expand Down
1 change: 0 additions & 1 deletion src/config/getAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
const getAll = async (options = {}) => {
const res = await api.post('config/show', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
...options
Expand Down
1 change: 0 additions & 1 deletion src/config/profiles/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function apply (profile, options = {}) {
const res = await api.post('config/profile/apply', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: profile,
Expand Down
1 change: 0 additions & 1 deletion src/config/profiles/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function list (options = {}) {
const res = await api.post('config/profile/list', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options),
headers: options.headers
Expand Down
1 change: 0 additions & 1 deletion src/config/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = configure(api => {
const signal = abortSignal(controller.signal, options.signal)

const res = await api.post('config/replace', {
timeout: options.timeout,
signal,
searchParams: toUrlSearchParams(options),
...(
Expand Down
1 change: 0 additions & 1 deletion src/config/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = configure(api => {
}

const res = await api.post('config', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(params),
headers: options.headers
Expand Down
1 change: 0 additions & 1 deletion src/dag/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function * dagExport (root, options = {}) {
const res = await api.post('dag/export', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: root.toString()
Expand Down
1 change: 0 additions & 1 deletion src/dag/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = configure(api => {
const { headers, body } = await multipartRequest(source, controller, options.headers)

const res = await api.post('dag/import', {
timeout: options.timeout,
signal,
headers,
body,
Expand Down
1 change: 0 additions & 1 deletion src/dag/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
const resolve = async (ipfsPath, options = {}) => {
const res = await api.post('dag/resolve', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: `${ipfsPath}${options.path ? `/${options.path}`.replace(/\/[/]+/g, '/') : ''}`,
Expand Down
1 change: 0 additions & 1 deletion src/dht/find-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = configure(api => {
*/
async function findPeer (peerId, options = {}) {
const res = await api.post('dht/findpeer', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: peerId,
Expand Down
1 change: 0 additions & 1 deletion src/dht/find-provs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = configure(api => {
*/
async function * findProvs (cid, options = {}) {
const res = await api.post('dht/findprovs', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: cid.toString(),
Expand Down
1 change: 0 additions & 1 deletion src/dht/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports = configure(api => {
*/
async function get (key, options = {}) {
const res = await api.post('dht/get', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: key instanceof Uint8Array ? uint8ArrayToString(key) : key,
Expand Down
1 change: 0 additions & 1 deletion src/dht/provide.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = configure(api => {
const cidArr = Array.isArray(cids) ? cids : [cids]

const res = await api.post('dht/provide', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: cidArr.map(cid => cid.toString()),
Expand Down
1 change: 0 additions & 1 deletion src/dht/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = configure(api => {
const signal = abortSignal(controller.signal, options.signal)

const res = await api.post('dht/put', {
timeout: options.timeout,
signal,
searchParams: toUrlSearchParams({
arg: uint8ArrayToString(key),
Expand Down
1 change: 0 additions & 1 deletion src/dht/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = configure(api => {
*/
async function * query (peerId, options = {}) {
const res = await api.post('dht/query', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: peerId.toString(),
Expand Down
1 change: 0 additions & 1 deletion src/diag/cmds.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function cmds (options = {}) {
const res = await api.post('diag/cmds', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options),
headers: options.headers
Expand Down
1 change: 0 additions & 1 deletion src/diag/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function net (options = {}) {
const res = await api.post('diag/net', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options),
headers: options.headers
Expand Down
1 change: 0 additions & 1 deletion src/diag/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function sys (options = {}) {
const res = await api.post('diag/sys', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(options),
headers: options.headers
Expand Down
1 change: 0 additions & 1 deletion src/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
const dns = async (domain, options = {}) => {
const res = await api.post('dns', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: domain,
Expand Down
1 change: 0 additions & 1 deletion src/files/chmod.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function chmod (path, mode, options = {}) {
const res = await api.post('files/chmod', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
Expand Down
1 change: 0 additions & 1 deletion src/files/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = configure(api => {
const sourceArr = Array.isArray(sources) ? sources : [sources]

const res = await api.post('files/cp', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: sourceArr.concat(destination).map(src => src instanceof CID ? `/ipfs/${src}` : src),
Expand Down
1 change: 0 additions & 1 deletion src/files/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = configure(api => {
}

const res = await api.post('files/flush', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
Expand Down
1 change: 0 additions & 1 deletion src/files/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = configure(api => {
}

const res = await api.post('files/ls', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path instanceof CID ? `/ipfs/${path}` : path,
Expand Down
1 change: 0 additions & 1 deletion src/files/mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function mkdir (path, options = {}) {
const res = await api.post('files/mkdir', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
Expand Down
1 change: 0 additions & 1 deletion src/files/mv.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = configure(api => {
}

const res = await api.post('files/mv', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: sources.concat(destination),
Expand Down
1 change: 0 additions & 1 deletion src/files/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = configure(api => {
*/
async function * read (path, options = {}) {
const res = await api.post('files/read', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
Expand Down
1 change: 0 additions & 1 deletion src/files/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function rm (path, options = {}) {
const res = await api.post('files/rm', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
Expand Down
1 change: 0 additions & 1 deletion src/files/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = configure(api => {
options = options || {}

const res = await api.post('files/stat', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
Expand Down
1 change: 0 additions & 1 deletion src/files/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = configure(api => {
*/
async function touch (path, options = {}) {
const res = await api.post('files/touch', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: path,
Expand Down
1 change: 0 additions & 1 deletion src/files/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = configure(api => {
const signal = abortSignal(controller.signal, options.signal)

const res = await api.post('files/write', {
timeout: options.timeout,
signal,
searchParams: toUrlSearchParams({
arg: path,
Expand Down
1 change: 0 additions & 1 deletion src/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = configure(api => {
}

const res = await api.post('get', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(opts),
headers: options.headers
Expand Down
1 change: 0 additions & 1 deletion src/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = configure(api => {
*/
async function id (options = {}) {
const res = await api.post('id', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: options.peerId ? options.peerId.toString() : undefined,
Expand Down
1 change: 0 additions & 1 deletion src/key/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function gen (name, options = { type: 'rsa', size: 2048 }) {
const res = await api.post('key/gen', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: name,
Expand Down
1 change: 0 additions & 1 deletion src/key/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = configure(api => {
*/
async function importKey (name, pem, password, options = {}) {
const res = await api.post('key/import', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: name,
Expand Down
Loading

0 comments on commit 8a498fe

Please sign in to comment.