Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoginAsync waiting Infinitely #134

Closed
pmsudhi opened this issue Apr 13, 2020 · 25 comments · Fixed by #136
Closed

LoginAsync waiting Infinitely #134

pmsudhi opened this issue Apr 13, 2020 · 25 comments · Fixed by #136

Comments

@pmsudhi
Copy link
Contributor

pmsudhi commented Apr 13, 2020

When I make a call to client.LoginAsync, the method never returns. The call in

var accessTokenResponse = await _requestor.Post<AccessTokenResponse>(url, accessTokenRequest);

in GitlabHttpFacade never returns.

Either my self hosted gitlab server blocked the API calls or some thing related to network happened , because my Client application using GitLabAPIClient was working fine until yesterday. Do you have any probable scenarios that may trigger this issue. In either case, the wait should do a timeout . Implemented Cancelation Token in POST request like below,

   public async Task<T> Post<T>(string url, object data = null)
   {
            **var ct = new CancellationTokenSource();
            ct.CancelAfter(3000);**

            StringContent content = SerializeToString(data);
            var responseMessage = await _client.PostAsync(url, content,ct.Token);
            await EnsureSuccessStatusCode(responseMessage);
            return await ReadResponse<T>(responseMessage);
    }

it works, but not fits to the existing code flow. Since I am very new to this API, just getting used to the workflow. The timeout value can be set at GitlabClient level, but putting this cancellation token in all request, must be there a better way to do this.

But the Big question, Why the Gitlab not returning the request? tried both Private key method and then calling client.Project.getAsync() , and issue is same. Iam able to access the Gitlab through browser, restarted my gitlab instance, but still same issue.

Also, When i make a URL request in browser, it returns Jsons
http://myserver/api/v4/projects

@jetersen
Copy link
Collaborator

jetersen commented Apr 13, 2020

What version of gitlab are you using?
What version of the gitlabapiclient are you using?

@jetersen
Copy link
Collaborator

Depending on how many projects you have it could take a while to return the result from client.project.GetAsync() as it will handle pagination and depending on how many projects you have, you can wait a good while.

@jetersen
Copy link
Collaborator

Can you show me the code you written so far to get projects?

If your not careful you could be running code against gitlab.com which will definitely take a while to return projects 😆

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

What version of gitlab are you using?
What version of the gitlabapiclient are you using?

Gitlab version :12.9.2
Apiclient 1.5

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

Depending on how many projects you have it could take a while to return the result from client.project.GetAsync() as it will handle pagination and depending on how many projects you have, you can wait a good while.

Iam connecting to my Local self hosted instance which have 99 projects.
Also, It is not related to getasync of project , even the loginAsync with username and password also stuck there

@jetersen
Copy link
Collaborator

If it's your own self hosted what sort of config do you have?

And why are you not using a token if so?

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

Can you show me the code you written so far to get projects?

If your not careful you could be running code against gitlab.com which will definitely take a while to return projects

Iam connecting to my local server which have 99 projects. Also, issue is same if i call LoginAsync method.
This is not a new application, but was working fine until yesterday.

@jetersen
Copy link
Collaborator

yesterday? did you upgrade your gitlab since?

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

If it's your own self hosted what sort of config do you have?

And why are you not using a token if so?
Iam not sure what information from configuration you need, will provide accordingly.
Actual application uses token only, when it stopped returning project list, i created another sample application, which uses LoginAsync . It just doesn't that. Nothing else. That got stuck.

Now if I put http://my server/api/v4/projects in browser , it does return the JSON

@jetersen
Copy link
Collaborator

That doesn't really tell me anything useful @pmsudhi

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

yesterday? did you upgrade your gitlab since?

Nope. Gitlab was.updated 2 week ago I guess. Not able to make any guess what would have changed. That is the reason why created new test application just by calling LoginAsync.

@jetersen
Copy link
Collaborator

Did the token expire? Did the token get revoked? Are you handling when your oauth token expires?

@jetersen
Copy link
Collaborator

jetersen commented Apr 13, 2020

What authentication schema have you setup on your gitlab instance? LDAP? own user database?

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

What authentication schema have you setup on your gitlab instance? LDAP? own user database?

own user database.
Let me clarify the workflow here. Below is the code snippet from my test application

Gitlab1

When I open the Browser I See this
Gitlab

And inside the Gitlabclient it is stuck here
Gitlab2

When i call API from browser, below is the result
gitlab3

My nuget package is like this
gitlab4

Regarding the Token Expiration, If i create a new application, but Same credentials, dosen't it give new set of Auth token?

@jetersen
Copy link
Collaborator

jetersen commented Apr 13, 2020

Not sure what to tell you, the integration test for login passes just fine even against the latest version of gitlab.

Is this code run against netframework 4.8 or dotnet core 3?

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

Not sure what to tell you, the integration test for login passes just fine even against the latest version of gitlab.

Is this code run against netframework 4.8 or dotnet core 3?

Actual code is .NET Standard 2.0 Class library and the test application is .net core 3.1 Windows Application

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

Not sure what to tell you, the integration test for login passes just fine even against the latest version of gitlab.
Is this code run against netframework 4.8 or dotnet core 3?

Actual code is .NET Standard 2.0 Class library and the test application is .net core 3.1 Windows Application

Got Some additional Information. I ran Fiddler to trace the traffic and it appears, Gitlab does responded with data. Following is the details

REQUEST

POST http://192.168.1.65/oauth/token HTTP/1.1
Host: 192.168.1.65
Content-Type: application/json
Content-Length: 85

{"grant_type":"password","scope":"api","username":"Sudheesh","password":"Password123"}

Response

HTTP/1.1 200 OK
Server: nginx
Date: Mon, 13 Apr 2020 17:03:23 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 226
Connection: keep-alive
Cache-Control: private, no-store
Etag: W/"7e7a7f8927abd8e0e12c365f8d2e5846"
Pragma: no-cache
X-Request-Id: Pce10oq0Dx6
X-Runtime: 0.054478
Strict-Transport-Security: max-age=31536000
Referrer-Policy: strict-origin-when-cross-origin

{"access_token":"1c776db2518298a97e85c33b60f05f418586898dbe5e5bc868d16b46d78336e3","token_type":"Bearer","refresh_token":"114486864b48c9578a2eff1783046b7121f9743c77b8fdf32da2994ba4b63cde","scope":"api","created_at":1572591624}

The response received within 1s as below
gitlab5

@jetersen
Copy link
Collaborator

So your application actually get's stuck on the lock and not the request itself?

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

So your application actually get's stuck on the lock and not the request itself?

No. The Arrow is little misplaced in the snapshot. :) . It never hits the lock. the call
var accessTokenResponse = await _requestor.Post<AccessTokenResponse>(url, accessTokenRequest);
never returns, while the fiddler log shows, data is actually returned

@jetersen
Copy link
Collaborator

Not sure why it would get stuck than as you can see for #135 it passes fine.
Here the test that it runs:
https://github.com/nmklotas/GitLabApiClient/blob/master/test/GitLabApiClient.Test/GitLabClientTest.cs#L64

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

Not sure why it would get stuck than as you can see for #135 it passes fine.
Here the test that it runs:
https://github.com/nmklotas/GitLabApiClient/blob/master/test/GitLabApiClient.Test/GitLabClientTest.cs#L64

Yeh. Had seen that case. In My system it is like this,
https://drive.google.com/file/d/1fmsgyGcNmlNoUURrmXRDRjrTE1_JijDd/view

@jetersen
Copy link
Collaborator

I cannot replicate the issue. 🤷‍♂️

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

Manged to find the problem . remember the discussion here #131 (comment)

After this, I had removed Task.Run from my code . Since my calls are from non async methods , the direct call to LoginAsync was /may resulting in a deadlock.

When I call Task.Run, the task created may be in the current context(just like we face problem when accessing GUI from threads). So when I called,

Task tsk = client.LoginAsync("Sudheesh", "Password123");
it resulted in deadlock.

but when I called
Task tsk = Task.Run(() => client.LoginAsync("Sudheesh", "Password123"));

it worked.

@jetersen
Copy link
Collaborator

Change your code to call from an async method so you can enjoy async/await code.

@pmsudhi
Copy link
Contributor Author

pmsudhi commented Apr 13, 2020

Change your code to call from an async method so you can enjoy async/await code.

I Wish i could. Unfortunately not all use cases can have that luxury. :(

Any ways thanks for the support.closing this issue now.

@pmsudhi pmsudhi closed this as completed Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants