Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[ssl] Reading from non-blocking socket wrapped by SSLContext returns an empty bytes object in case if the client stays connected #125637

Open
Labels
stdlibPython modules in the Lib dirtopic-SSLtype-bugAn unexpected behavior, bug, or error
@intrelator

Description

@intrelator

Bug report

Bug description:

I run my client-server application using SSLContext. And during communication I faced with situation when I receive an empty bytes object from the socket on server side. But in Wireshark dump I can see that client is present and sends data. If I add some delay after I receive empty bytes and try read from socket again I get some data. My code properly works on python 3.8 but it fails on 3.12. Also I tested without ssl on 3.12 and it works fine.

# how the socket initiated:context=ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)context.load_cert_chain(*ssl_context)self.socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)self.socket.bind((host,port))self.socket.listen(1)self.socket=context.wrap_socket(self.socket,server_side=True)# how I accept client:whilenotTrue:self.socket.settimeout(1)try:self.connection,_=self.socket.accept()self.connection.settimeout(0.01)breakexcept (socket.timeout,ssl.SSLError):continue# how I read the data:defread_data(self):data=b''ifself.connectionisnotNone:try:print(f"start recv at:{datetime.now().isoformat()}")ifdata:=self.connection.recv(256):print(f"finish recv at:{datetime.now().isoformat()}")returndataelse:print(f"no data at:{datetime.now().isoformat()}")self.connection=Nonereturnb''except (socket.timeout,OSError):returndatareturndata

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-SSLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp