Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket receiveFrame() keeps returning the same frame when no payload (flags/header only) #4884

Open
thunderbolt10 opened this issue Feb 27, 2025 · 2 comments
Assignees

Comments

@thunderbolt10
Copy link

After upgrading Poco from 1.13 to 1.14.1 client websockets now constantly loop on receive continuously reading the same header frame without completing or timeout.

There are 2 implementations of WebSocketImpl::receiveBytes. This issue relates to int WebSocketImpl::receiveBytes(Poco::Buffer<char>& buffer, int, const Poco::Timespan&) which is missing a call to skipHeader() if the payloadLength is zero. The same header therefore remains in the buffer the next time receiveBytes() is called.

To reproduce the socket must receive either a PING or PONG frame where the payloadLength is zero.

The other implementation of receiveBytes,
int WebSocketImpl::receiveBytes(void* buffer, int length, int) appears to be correct as it calls skipHeader for zero payloadLength.

if (payloadLength <= 0)
{
	skipHeader(_receiveState.headerLength);    
	return payloadLength;
}

A solution for the receiveBytes with Timespan implementation could be to move the call to skipHeader several lines forward so that it is always called regardless of payloadLength.

int WebSocketImpl::receiveBytes(Poco::Buffer<char>& buffer, int, const Poco::Timespan&)
{
	if (getBlocking())
	{
		int payloadLength = -1;
		while (payloadLength < 0)
		{
			payloadLength = peekHeader(_receiveState);
		}
		skipHeader(_receiveState.headerLength);             <--- move to here
		if (payloadLength <= 0)
		{
			return payloadLength;
		}
                // skipHeader(_receiveState.headerLength);         <--- original location

POCO version 1.14.1
OS Windows 11

@thunderbolt10 thunderbolt10 changed the title WebSocket receiveFrame() keeps returning the same frame when header only. WebSocket receiveFrame() keeps returning the same frame when flags/header only. Feb 27, 2025
@thunderbolt10 thunderbolt10 changed the title WebSocket receiveFrame() keeps returning the same frame when flags/header only. WebSocket receiveFrame() keeps returning the same frame when frame contains only flags/header and no payload. Feb 27, 2025
@matejk
Copy link
Contributor

matejk commented Feb 27, 2025

Related #4850.

Can you comment, @obiltschnig ?

@thunderbolt10 thunderbolt10 changed the title WebSocket receiveFrame() keeps returning the same frame when frame contains only flags/header and no payload. WebSocket receiveFrame() keeps returning the same frame when no payload (flags/header only) Feb 27, 2025
@obiltschnig obiltschnig self-assigned this Feb 27, 2025
@obiltschnig obiltschnig added this to the Release 1.14.2 milestone Feb 27, 2025
@obiltschnig
Copy link
Member

Bug, probably.

obiltschnig added a commit that referenced this issue Feb 27, 2025
obiltschnig added a commit that referenced this issue Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants