question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

github closes stream after token request

See original GitHub issue

When I try to authenticate using GitHubOAuthenticator I always get Exception “Stream closed”. It happens at step 2 of OAuth2 process - “https://github.com/login/oauth/authorize” executes normally and returns code, but when authenticator tries to fetch “https://github.com/login/oauth/access_token?client_id=…” exception is thrown. I found out that it happens in “tornado/simple_httpclient.py” when _write_body method tries to await self.connection.read_response(self).

Although:

  1. I tried to fetch other arbitrary URLs from within GitHubOAuthenticator’ authenticate method - it works fine.
  2. I tried to fetch GitHub’s token manually with the help of curl - it works fine.
  3. I even found and tried to use YandexPassportOAuthenticator which has almost identical code - it works fine!

Does anyone have any ideas why this can happen?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kpflemingcommented, Jun 6, 2019

Found the solution: the ‘simple’ HTTP client in Tornado doesn’t work for the access_token request which is made to GitHub; configuring Tornado to use curl_httpclient instead (which requires installing pycurl as well) results in successful logins.

Adding these two lines to jupyterhub_config.py will take care of it:

from tornado.httpclient import AsyncHTTPClient
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
0reactions
minrkcommented, Jun 28, 2019

Will do. And thanks for finding that curl is a valid workaround! Curl is indeed recommended in production if you have quite a few users, for performance reasons as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UploadAsync closes the stream · Issue #38 - GitHub
But first request failed due to expired tokens and stream get closed. As a result, repeated request failed too, due to closed stream....
Read more >
Stream Breaks · Issue #72 · thisbejim/Pyrebase - GitHub
To resolve this we will have to figure out how to apply fresh auth tokens to our stream session without closing the stream...
Read more >
Stream.CloseAsync method #31561 - dotnet/runtime - GitHub
This method would allow to implement close operation that can be ... clean up after the stream if the token had cancellation requested....
Read more >
Exception when bi-directional stream get´s closed by client
Hello, i have tried to find a way preventing to following exception. By using an bi-directional stream i got this exception outside of...
Read more >
Stuck on "Fetching closed dates for issues" #965 - GitHub
When I cancel with ctrl + c it just says interrupt, 'block in make_fiber`. not sure what's that... My github_changelog_generator version is: 1.16.2...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found