gitbeaker icon indicating copy to clipboard operation
gitbeaker copied to clipboard

Is there a way to set a custom timeout on a request?

Open chris-dura opened this issue 5 years ago • 4 comments

Description

I'm trying to list the repository trees for some projects.

However, some not-so-nice person(s) have checked their node_modules into their repo 😡 Basically, getting the tree for those repos can take waaaaaay too long... the script won't crash, but I'd prefer to just move on, and flag that repo to get a slap on the wrist later.

I see a requestTimeout property in the ProjectsBundle object... is there any way to set a custom timeout so that if it takes too long it'll just throw a timeout error or something?

Steps to reproduce

import { ProjectsBundle } from 'gitlab';
 
const api = new ProjectsBundle({
  host:   'http://example.com',
  token: 'personaltoken'
});
 
let project1 = await api.Repositories.tree(1, {recursive: true});
let project2 = await api.Repositories.tree(2, {recursive: true});
let project3 = await api.Repositories.tree(3, {recursive: true});
...

Expected behaviour

Actual behaviour

Possible fixes

chris-dura avatar Dec 18 '19 19:12 chris-dura

Thats what the requestTimeout option would be used for, but it would be applied to all requests. Could you give me an example of how you would want it to work if the current timeout functionality isnt sufficient?

jdalrymple avatar Dec 19 '19 14:12 jdalrymple

requestTimeout is per request what you want is timeout per method call.

Since tree recursive is heavily paginated node-gitlab sends a request for each page and gitlab is limiting each request to 100 results per page.

jetersen avatar Dec 19 '19 14:12 jetersen

Could you give me an example of how you would want it to work if the current timeout functionality isnt sufficient?

@jdalrymple -- thanks, so I might be missing something... I didn't see any docs on how I could shorten requestTimeout or use "the current timeout functionality"?

Also, I wasn't sure that would do what I wanted (seems to be indicated by @casz as well), because a console log seems like the ProjectsBundle.requestTimeout was set to 300000 (ish) which I assume is in milliseconds, meaning about 5 min. However, when I would walk away for many minutes... well beyond the 5... and when I came back the script was still "chewing" on getting the tree, and from what I could tell, did not timeout after the 5 min.

@casz -- Soooo... if I'm understanding you correctly... if a single page of the tree (request) took longer than ProjectsBundle.requestTimeout, then it would timeout? So, I actually need to a set a timeout for getting all the pages in the tree? Is that possible?

chris-dura avatar Dec 20 '19 02:12 chris-dura

Yea that should be possible. I never did take into consideration the paginated requests in terms of the timeout. In those cases, it would make sense that the default behaviour for a timeout be applied to the method your calling, regardless of how many requests there are? @casz

jdalrymple avatar Dec 21 '19 09:12 jdalrymple

:rocket: Issue was released in 38.8.0 :rocket:

jdalrymple avatar May 22 '23 04:05 jdalrymple