Skip to content

Conversation

liuyangc3
Copy link

No description provided.

@aaugustin
Copy link
Member

You didn't explain why you're proposing this, making it hard for me to tell if it's the right solution.

Technically, your code will break if ping_timeout is None and you don't receive a pong within ping_interval.

@aaugustin
Copy link
Member

The next step would be for me to understand what is the purpose of this feature and to decide whether I want to support it in the library.

@aaugustin
Copy link
Member

You may be proposing this because some servers require clients to send a ping with a specific content at a minimum frequency. However, most of those servers expect it in a Text frame, not a Ping frame. With the proposed ping_data API, users are likely to get confused.

Servers relying on protocol-level ping/pong in Ping/Pong frames, as opposed to application-level ping/pong in Text frames, usually don't care about the content of pings and pongs. websockets has been sending random 4-bytes payloads in pings for a decade without issues.

@liuyangc3
Copy link
Author

liuyangc3 commented Sep 20, 2025

Hi @aaugustin In some backend implement, server doesn't response the ping when the ping data is not a str type, which cause a pong timeout and connection close exception on client side. new TCP connection is recreated after each ping interval.

The ping data in keep_alive imeplement is forced to random bytes. In my case, I tried to hardcode self.ping("") and connection is back to normal.

The the protocal desgin itself provides ability to custom the ping data in send_ping() method, but the current high-level imeplement, which lose the ability, that's why this PR proposing for.

@liuyangc3
Copy link
Author

liuyangc3 commented Sep 20, 2025

You may be proposing this because some servers require clients to send a ping with a specific content at a minimum frequency. However, most of those servers expect it in a Text frame, not a Ping frame. With the proposed ping_data API, users are likely to get confused.

Servers relying on protocol-level ping/pong in Ping/Pong frames, as opposed to application-level ping/pong in Text frames, usually don't care about the content of pings and pongs. websockets has been sending random 4-bytes payloads in pings for a decade without issues.

Yeah, but random 4-bytes payloads not suite for all caces, we just need a way to allow user control the keep alive behaviour, maybe there's better proposal

@aaugustin
Copy link
Member

aaugustin commented Sep 20, 2025

some backend implement, server doesn't response the ping when the ping data is not a str type, which cause a pong timeout

I guess "not a str type" means "not valid UTF-8"; this is a clear spec violation as explained here: #922 (comment); those servers are buggy and need to be fixed.

Alternatively, you can disable pings with ping_interval=None.

I'm not going to complexify the API because "some backend implement" is buggy. The API has a lot of parameters already; I'm not adding new ones without a very strong reason.

If I wanted to make a change, I'd send a random ASCII string rather than random bytes. Until now, getting buggy servers to fix their bugs has worked for me :-)

@aaugustin aaugustin closed this Sep 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants