René's URL Explorer Experiment


Title: BlobReader not buffering properly. · Issue #462 · googleapis/python-storage · GitHub

Open Graph Title: BlobReader not buffering properly. · Issue #462 · googleapis/python-storage

X Title: BlobReader not buffering properly. · Issue #462 · googleapis/python-storage

Description: Environment details OS type and version: Mac 10.15.7 Python version: Python 3.9.5 pip version: pip 21.1.1 google-cloud-storage: Version: 1.38.0 Steps to reproduce When trying to stream a file from Google Cloud Storage to Google Drive, th...

Open Graph Description: Environment details OS type and version: Mac 10.15.7 Python version: Python 3.9.5 pip version: pip 21.1.1 google-cloud-storage: Version: 1.38.0 Steps to reproduce When trying to stream a file from ...

X Description: Environment details OS type and version: Mac 10.15.7 Python version: Python 3.9.5 pip version: pip 21.1.1 google-cloud-storage: Version: 1.38.0 Steps to reproduce When trying to stream a file from ...

Opengraph URL: https://github.com/googleapis/python-storage/issues/462

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"BlobReader not buffering properly.","articleBody":"#### Environment details\r\n\r\n  - OS type and version: Mac 10.15.7\r\n  - Python version: `Python 3.9.5`\r\n  - pip version: `pip 21.1.1` \r\n  - `google-cloud-storage`: `Version: 1.38.0` \r\n\r\n#### Steps to reproduce\r\n\r\nWhen trying to stream a file from Google Cloud Storage to Google Drive, the BlobReader doesn't appear to be buffering properly.\r\n\r\nReading through the blobReader code, it should buffer the file as per chunksize, then download new chuncks as that buffer is exausted. However my experience is that every time the blobwriter is read a 2nd time, it invalidates the buffer, and downloads a new chunk.\r\n\r\nthe Google API `MediaIoBaseUpload` appears to be requesting files in `8192` bytes chunks, and every time the next chunk is requested from the GCS BlobReader, it downloads the next 40Mb chunk, rather than reading from the buffer.\r\n\r\nMy debugging has found that the buffer is actually being invalided when the python HTTP class 'seeks' the next chunk, and the math is failing [here](https://github.com/googleapis/python-storage/blob/master/google/cloud/storage/fileio.py#L155), however, i'm unsure what should be happening.\r\n\r\nCode example below demonstrates the problem, just provide your own client credentials for Drive, and upload a CSV file to Google Cloud storage, and note the blob and bucket.\r\n\r\n#### Code example\r\n\r\n```python\r\nfrom google.cloud import storage\r\nfrom googleapiclient.http import MediaIoBaseUpload\r\nfrom googleapiclient.discovery import build\r\nfrom google_auth_oauthlib.flow import InstalledAppFlow\r\nfrom google.auth.transport.requests import Request\r\nfrom google.oauth2.credentials import Credentials\r\nimport os\r\nimport logging\r\nimport sys\r\n\r\nlogging.basicConfig(stream=sys.stdout, level=logging.DEBUG)\r\n\r\nlogger = logging.getLogger(__name__)\r\n\r\nSCOPES = ['https://www.googleapis.com/auth/drive']\r\n\r\n\r\ndef getCreds():\r\n    creds = None\r\n    # The file token.json stores the user's access and refresh tokens, and is\r\n    # created automatically when the authorization flow completes for the first\r\n    # time.\r\n    if os.path.exists('token.json'):\r\n        creds = Credentials.from_authorized_user_file('token.json', SCOPES)\r\n    # If there are no (valid) credentials available, let the user log in.\r\n    if not creds or not creds.valid:\r\n        if creds and creds.expired and creds.refresh_token:\r\n            creds.refresh(Request())\r\n        else:\r\n            flow = InstalledAppFlow.from_client_secrets_file(\r\n                'client_secret.json', SCOPES)\r\n            creds = flow.run_local_server(port=0)\r\n        # Save the credentials for the next run\r\n        with open('token.json', 'w') as token:\r\n            token.write(creds.to_json())\r\n    \r\n    return creds\r\n\r\ndef gcsToDrive(bucketName, blobName):\r\n    client = storage.Client()\r\n\r\n    bucket = client.get_bucket(bucketName)\r\n    blob = bucket.blob(blobName)\r\n\r\n    creds = getCreds()\r\n\r\n    service = build('drive', 'v3', credentials=creds)\r\n\r\n    megabyte = (256 * 1024) * 4\r\n    chunk_size: int = megabyte * 40\r\n\r\n    with blob.open(\"rb\", chunk_size=chunk_size) as stream:\r\n        file_metadata = {\r\n            \"name\": \"My Report\",\r\n            \"mimeType\": \"application/vnd.google-apps.spreadsheet\",\r\n        }\r\n        media = MediaIoBaseUpload(stream, mimetype=\"text/csv\", resumable=True, chunksize=chunk_size)\r\n        file = (\r\n            service.files()\r\n            .create(body=file_metadata, media_body=media, fields=\"id\")\r\n            .execute()\r\n        )\r\n\r\n    logger.info(file)\r\n    \r\n    return file\r\n\r\nif __name__ == \"__main__\":\r\n    my_bucket = \"my_bucked\"\r\n    my_blob = \"my-blob.csv\"\r\n\r\n    gcsToDrive(my_bucket, my_blob)\r\n```\r\n\r\n#### Example Logs\r\n```\r\nDEBUG:google.auth._default:Checking /Users/\u003cusername\u003e/code/python/gscFileError/sa.json for explicit credentials as part of auth process...\r\nDEBUG:google.auth._default:Checking /Users/\u003cusername\u003e/code/python/gscFileError/sa.json for explicit credentials as part of auth process...\r\nDEBUG:urllib3.util.retry:Converted retries value: 3 -\u003e Retry(total=3, connect=None, read=None, redirect=None, status=None)\r\nDEBUG:google.auth.transport.requests:Making request: POST https://oauth2.googleapis.com/token\r\nDEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): oauth2.googleapis.com:443\r\nDEBUG:urllib3.connectionpool:https://oauth2.googleapis.com:443 \"POST /token HTTP/1.1\" 200 None\r\nDEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): storage.googleapis.com:443\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /storage/v1/b/\u003cmy bucket\u003e?projection=noAcl\u0026prettyPrint=false HTTP/1.1\" 200 574\r\nINFO:googleapiclient.discovery_cache:file_cache is only supported with oauth2client\u003c4.0.0\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?projection=noAcl\u0026prettyPrint=false HTTP/1.1\" 200 738\r\nDEBUG:googleapiclient.discovery:URL being requested: POST https://www.googleapis.com/upload/drive/v3/files?fields=id\u0026alt=json\u0026uploadType=resumable\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 2240745\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 2224361\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 2207977\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 2191593\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 2175209\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 2158825\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 2142441\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 2126057\r\n...\r\n...\r\n...\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 94441\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 78057\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 61673\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 45289\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 28905\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 206 12521\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 416 29\r\nDEBUG:urllib3.connectionpool:https://storage.googleapis.com:443 \"GET /download/storage/v1/b/\u003cmy bucket\u003e/o/my-blob.csv?generation=1623219180016524\u0026alt=media HTTP/1.1\" 416 29\r\nINFO:__main__:{'id': '19GXqCAQDsRtK1czPSB_vX_SaBp4JtatlxCl4uQUU66o'}\r\n```\r\n","author":{"url":"https://github.com/Megabytemb","@type":"Person","name":"Megabytemb"},"datePublished":"2021-06-10T03:05:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/462/python-storage/issues/462"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:94233bbf-3863-a027-fade-62f1fe4b71a3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC2A8:1846F5:EC07DA:F13AA7:6A4DC402
html-safe-noncef5e242999bdefb2121ef7ecc7ede324260f68862ddbbbe6b144f7e87bb5cc2f1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkE4OjE4NDZGNTpFQzA3REE6RjEzQUE3OjZBNERDNDAyIiwidmlzaXRvcl9pZCI6IjM2MjYzMTIzODM4MjE4OTA1NjIiLCJyZWdpb25fZWRnZSI6InNlYSIsInJlZ2lvbl9yZW5kZXIiOiJzZWEifQ==
visitor-hmac13e09549fb9f91ce63d4a2ba3db873e0fbc35e4eeed3783395880c9d6e5f6338
hovercard-subject-tagissue:916840029
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-storage/462/issue_layout
twitter:imagehttps://opengraph.githubassets.com/08b6dda46e326cec570b80526f29b3d812001f9d850e69265207a59792df54d3/googleapis/python-storage/issues/462
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/08b6dda46e326cec570b80526f29b3d812001f9d850e69265207a59792df54d3/googleapis/python-storage/issues/462
og:image:altEnvironment details OS type and version: Mac 10.15.7 Python version: Python 3.9.5 pip version: pip 21.1.1 google-cloud-storage: Version: 1.38.0 Steps to reproduce When trying to stream a file from ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameMegabytemb
hostnamegithub.com
expected-hostnamegithub.com
None06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33
turbo-cache-controlno-preview
go-importgithub.com/googleapis/python-storage git https://github.com/googleapis/python-storage.git
octolytics-dimension-user_id16785467
octolytics-dimension-user_logingoogleapis
octolytics-dimension-repository_id226992639
octolytics-dimension-repository_nwogoogleapis/python-storage
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id226992639
octolytics-dimension-repository_network_root_nwogoogleapis/python-storage
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release1d344bdb7547fe6bca17a59bb2b8aac3dc9532a0
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/googleapis/python-storage/issues/462#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-storage%2Fissues%2F462
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-storage%2Fissues%2F462
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=googleapis%2Fpython-storage
Reloadhttps://github.com/googleapis/python-storage/issues/462
Reloadhttps://github.com/googleapis/python-storage/issues/462
Reloadhttps://github.com/googleapis/python-storage/issues/462
Please reload this pagehttps://github.com/googleapis/python-storage/issues/462
googleapis https://github.com/googleapis
python-storagehttps://github.com/googleapis/python-storage
Notifications https://github.com/login?return_to=%2Fgoogleapis%2Fpython-storage
Fork 172 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-storage
Star 502 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-storage
Code https://github.com/googleapis/python-storage
Issues 0 https://github.com/googleapis/python-storage/issues
Pull requests 0 https://github.com/googleapis/python-storage/pulls
Actions https://github.com/googleapis/python-storage/actions
Projects https://github.com/googleapis/python-storage/projects
Security and quality 0 https://github.com/googleapis/python-storage/security
Insights https://github.com/googleapis/python-storage/pulse
Code https://github.com/googleapis/python-storage
Issues https://github.com/googleapis/python-storage/issues
Pull requests https://github.com/googleapis/python-storage/pulls
Actions https://github.com/googleapis/python-storage/actions
Projects https://github.com/googleapis/python-storage/projects
Security and quality https://github.com/googleapis/python-storage/security
Insights https://github.com/googleapis/python-storage/pulse
#721https://github.com/googleapis/python-storage/pull/721
BlobReader not buffering properly.https://github.com/googleapis/python-storage/issues/462#top
#721https://github.com/googleapis/python-storage/pull/721
https://github.com/andrewsg
api: storageIssues related to the googleapis/python-storage API.https://github.com/googleapis/python-storage/issues?q=state%3Aopen%20label%3A%22api%3A%20storage%22
status: investigatingThe issue is under investigation, which is determined to be non-trivial.https://github.com/googleapis/python-storage/issues?q=state%3Aopen%20label%3A%22status%3A%20investigating%22
type: questionRequest for information or clarification. Not an issue.https://github.com/googleapis/python-storage/issues?q=state%3Aopen%20label%3A%22type%3A%20question%22
https://github.com/Megabytemb
Megabytembhttps://github.com/Megabytemb
on Jun 10, 2021https://github.com/googleapis/python-storage/issues/462#issue-916840029
herehttps://github.com/googleapis/python-storage/blob/master/google/cloud/storage/fileio.py#L155
andrewsghttps://github.com/andrewsg
api: storageIssues related to the googleapis/python-storage API.https://github.com/googleapis/python-storage/issues?q=state%3Aopen%20label%3A%22api%3A%20storage%22
status: investigatingThe issue is under investigation, which is determined to be non-trivial.https://github.com/googleapis/python-storage/issues?q=state%3Aopen%20label%3A%22status%3A%20investigating%22
type: questionRequest for information or clarification. Not an issue.https://github.com/googleapis/python-storage/issues?q=state%3Aopen%20label%3A%22type%3A%20question%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.