GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sendfile for sockets neglects pseudo files on Linux · Issue #93300 · python/cpython

sendfile for sockets neglects pseudo files on Linux #93300

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
sendfile for sockets neglects pseudo files on Linux#93300
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@illia-v
illia-v
opened on May 27, 2022
Issue body actions

Bug report

socket.socket.sendfile and asyncio.base_events.BaseEventLoop.sock_sendfile rely on st_size to determine an amount of bytes to be sent if count is not provided.

But st_size is equal to zero for pseudo files like /proc/cpuinfo on Linux. Therefore, the methods send no data for such files.

Related code

cpython/Lib/socket.py

Lines 355 to 360 in a637c09

try:
fsize = os.fstat(fileno).st_size
except OSError as err:
raise _GiveupOnSendfile(err) # not a regular file
if not fsize:
return 0 # empty file

cpython/Lib/asyncio/unix_events.py

Lines 361 to 367 in 13c10bf

try:
fsize = os.fstat(fileno).st_size
except OSError:
raise exceptions.SendfileNotAvailableError("not a regular file")
blocksize = count if count else fsize
if not blocksize:
return 0 # empty file

Example

Assuming nc -lkU some.sock and ./python -m asyncio run in the same directory:

>>> import asyncio
>>> import socket
>>> sock = socket.socket(socket.AF_UNIX)
>>> loop = asyncio.get_running_loop()
>>> await loop.sock_connect(sock, "./some.sock")
>>> with open("/proc/cpuinfo", "rb") as cpuinfo_file:
...     os.fstat(cpuinfo_file.fileno()).st_size
...     await loop.sock_sendfile(sock, cpuinfo_file)
...     sock.sendfile(cpuinfo_file)
...     len(cpuinfo_file.read())
... 
0
0
0
18294

Activity

  1. illia-v
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 27, 2022
  2. kumaraditya303 commented on Jun 14, 2022

    @kumaraditya303
    kumaraditya303
    on Jun 14, 2022
    Contributor
    More actions

    Do you have any fix for this or idea of how this could be fixed? Also are there any use-case of sending pseudo files through sendfile ?

  3. illia-v commented on Jun 17, 2022

    @illia-v
    illia-v
    on Jun 17, 2022
    ContributorAuthor
    More actions

    @kumaraditya303 I do not have any use case, and I have not looked for fixing options.

    I was exploring peculiarities of using the copy_file_range syscall for a pseudo file, and checked if a similar issue related to pseudo files exists in Python. That is how I found this issue.

  4. kumaraditya303 commented on Jun 19, 2022

    @kumaraditya303
    kumaraditya303
    on Jun 19, 2022
    Contributor
    More actions

    I don't think this is a bug and there is nothing actionable here so closing. However, this can be reopened if required.

  5. kumaraditya303
    closed this as not plannedon Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.