René's URL Explorer Experiment


Title: Error in BaseEventLoop._sock_sendfile_fallback with offset 0 · Issue #150107 · python/cpython · GitHub

Open Graph Title: Error in BaseEventLoop._sock_sendfile_fallback with offset 0 · Issue #150107 · python/cpython

X Title: Error in BaseEventLoop._sock_sendfile_fallback with offset 0 · Issue #150107 · python/cpython

Description: Bug report Bug description: BaseEventLoop._sock_sendfile_fallback (https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L971) erroneously doesn't seek when passed the offset 0. if offset: file.seek(offset) This check in...

Open Graph Description: Bug report Bug description: BaseEventLoop._sock_sendfile_fallback (https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L971) erroneously doesn't seek when passed the offset 0. if...

X Description: Bug report Bug description: BaseEventLoop._sock_sendfile_fallback (https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L971) erroneously doesn't seek when passed the offset 0...

Opengraph URL: https://github.com/python/cpython/issues/150107

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Error in BaseEventLoop._sock_sendfile_fallback with offset 0","articleBody":"# Bug report\n\n### Bug description:\n\n`BaseEventLoop._sock_sendfile_fallback` (https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L971) erroneously doesn't seek when passed the offset 0.\n```python\n        if offset:\n            file.seek(offset)\n```\nThis check in the function doesn't call `file.seek` if offset is falsey. If the file in question has a file pointer that is not currently at the 0 offset then this will erroneously send from the current offset and not the start of the file as desired. This can happen when `sendfile` is called with the destination socket is an SSL socket.\n\nRepro code (generated by Claude), because of needing to create an SSL socket it's a bit involved - including making a self signed cert with the openssl command.\n```python\nimport asyncio\nimport os\nimport ssl\nimport subprocess\nimport sys\nimport tempfile\nfrom pathlib import Path\n\nCONTENT = b\"X\" * 1000\n\n\ndef make_throwaway_cert(tmp: Path) -\u003e tuple[Path, Path]:\n    cert = tmp / \"cert.pem\"\n    key = tmp / \"key.pem\"\n    subprocess.run(\n        [\n            \"openssl\", \"req\", \"-x509\", \"-newkey\", \"rsa:2048\", \"-nodes\",\n            \"-keyout\", str(key), \"-out\", str(cert),\n            \"-days\", \"1\", \"-subj\", \"/CN=localhost\",\n        ],\n        check=True,\n        capture_output=True,\n    )\n    return cert, key\n\n\nasync def main() -\u003e int:\n    with tempfile.TemporaryDirectory() as tmp_:\n        tmp = Path(tmp_)\n        cert, key = make_throwaway_cert(tmp)\n\n        data_path = tmp / \"data\"\n        data_path.write_bytes(CONTENT)\n\n        # SSL server that drains whatever it receives.\n        server_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)\n        server_ctx.load_cert_chain(cert, key)\n        received = 0\n        done = asyncio.Event()\n\n        async def handle(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -\u003e None:\n            nonlocal received\n            try:\n                while chunk := await reader.read(4096):\n                    received += len(chunk)\n            finally:\n                writer.close()\n                done.set()\n\n        server = await asyncio.start_server(handle, \"127.0.0.1\", 0, ssl=server_ctx)\n        port = server.sockets[0].getsockname()[1]\n\n        # SSL client → transport's `_sendfile_compatible == UNSUPPORTED` → fallback path.\n        client_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)\n        client_ctx.check_hostname = False\n        client_ctx.verify_mode = ssl.CERT_NONE\n        _, writer = await asyncio.open_connection(\n            \"127.0.0.1\", port, ssl=client_ctx, server_hostname=\"localhost\"\n        )\n\n        # Open the file and pre-advance its position. In the real-world bug\n        # this happens because the calling code previously read through the\n        # same fh (e.g. to parse an HTTP header).\n        f = open(data_path, \"rb\", buffering=0)\n        f.seek(len(CONTENT))  # file position is at EOF\n\n        # Send from offset=0. Expectation: 1000 bytes transferred.\n        loop = asyncio.get_running_loop()\n        sent = await loop.sendfile(writer.transport, f, offset=0)\n\n        writer.close()\n        await writer.wait_closed()\n        await done.wait()\n        server.close()\n        await server.wait_closed()\n        f.close()\n\n        print(f\"Python:       {sys.version}\")\n        print(f\"file size:    {len(CONTENT)}\")\n        print(f\"file.tell() before sendfile: {len(CONTENT)} (EOF)\")\n        print(f\"loop.sendfile(..., offset=0) returned: {sent}\")\n        print(f\"server received: {received} bytes\")\n        print()\n\n        if sent == 0 and received == 0:\n            print(\"BUG REPRODUCED: offset=0 was ignored; the fallback read from \"\n                  \"file.tell() instead of from the requested offset.\")\n            return 1\n        else:\n            print(\"Bug NOT reproduced on this Python build.\")\n            return 0\n\n\nsys.exit(asyncio.run(main()))\n```\nThe relevant lines are the line `f.seek(len(CONTENT))` and the line `sent = await loop.sendfile(writer.transport, f, offset=0)`. Most of the rest is setup and teardown.\n\n### CPython versions tested on:\n\n3.12, 3.13\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-150142\n* gh-150259\n* gh-150270\n* gh-150569\n* gh-150570\n* gh-150571\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/SteveJones","@type":"Person","name":"SteveJones"},"datePublished":"2026-05-19T19:42:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/150107/cpython/issues/150107"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:82035cc0-43cc-02e0-9ab4-1e64bb7c659c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD25E:33952:6135745:884CD8F:6A50212E
html-safe-noncef6f38dbbded7c49ffd125c2c9e8faabda481209fa7153d75892003668a8daa17
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjVFOjMzOTUyOjYxMzU3NDU6ODg0Q0Q4Rjo2QTUwMjEyRSIsInZpc2l0b3JfaWQiOiI3MjEwODQ2MTgwMTU4MjE4NTQyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmace7d6eecfb6bb7883a2151d8d14ce9538ac6900f3cf019b63603d675d3a5edc8f
hovercard-subject-tagissue:4480474781
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/python/cpython/150107/issue_layout
twitter:imagehttps://opengraph.githubassets.com/48bad39ac84d56d2ab6ea0d315fca743149b58e355f2b836f34776b886ef0f06/python/cpython/issues/150107
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/48bad39ac84d56d2ab6ea0d315fca743149b58e355f2b836f34776b886ef0f06/python/cpython/issues/150107
og:image:altBug report Bug description: BaseEventLoop._sock_sendfile_fallback (https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L971) erroneously doesn't seek when passed the offset 0. if...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameSteveJones
hostnamegithub.com
expected-hostnamegithub.com
Nonea08040246389072795e3b4e7b33c6d9a0c564eee02e829a809326d67c418b069
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
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
released1b91b18e7330fc458dfd824c61eaed7daa830d6
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/150107#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F150107
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/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/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/enterprise/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%2Fpython%2Fcpython%2Fissues%2F150107
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=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/150107
Reloadhttps://github.com/python/cpython/issues/150107
Reloadhttps://github.com/python/cpython/issues/150107
Please reload this pagehttps://github.com/python/cpython/issues/150107
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/150107
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.6k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Error in BaseEventLoop._sock_sendfile_fallback with offset 0https://github.com/python/cpython/issues/150107#top
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-asynciohttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-asyncio%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/SteveJones
SteveJoneshttps://github.com/SteveJones
on May 19, 2026https://github.com/python/cpython/issues/150107#issue-4480474781
https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L971https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L971
gh-150107: adding hasattr check on offset to include if available #150142https://github.com/python/cpython/pull/150142
gh-150107: Fix asyncio sendfile fallback ignoring non-zero offset #150259https://github.com/python/cpython/pull/150259
gh-150107: Fix asyncio sendfile fallback ignoring non-zero offset #150270https://github.com/python/cpython/pull/150270
[3.14] gh-150107: Fix asyncio sendfile fallback ignoring non-zero offset (GH-150270) #150569https://github.com/python/cpython/pull/150569
[3.15] gh-150107: Fix asyncio sendfile fallback ignoring non-zero offset (GH-150270) #150570https://github.com/python/cpython/pull/150570
[3.13] gh-150107: Fix asyncio sendfile fallback ignoring non-zero offset (GH-150270) #150571https://github.com/python/cpython/pull/150571
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-asynciohttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-asyncio%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
asynciohttps://github.com/orgs/python/projects/29
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.