Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Allowed uploading files more than 65536 bytes. #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

petroakzhygitov
Copy link

sendWindowSize was never updated with new stream.windowSize value

…er updated with new stream.windowSize value
@kgoodier
Copy link
Contributor

_sessionSendWindowSize represents the window size the remote side will accept for the session. It needs to be decremented for each send so the sender doesn't overflow the remote's window size. It's expected the remote sends back WINDOW_UPDATE frames with stream-id set to 0 to increase the _sessionSendWindowSize in the sender.

@petroakzhygitov
Copy link
Author

Ok. But there is still a problem with uploading files more than 65536 bytes.

There is a function:

  • (void)didReadWindowUpdateFrame:(SPDYWindowUpdateFrame )windowUpdateFrame frameDecoder:(SPDYFrameDecoder *)frameDecoder
    {
    /

    • SPDY WINDOW_UPDATE frame processing requirements:
      *
    • Receivers of a WINDOW_UPDATE that cause the window size to exceed 2^31
    • must send a RST_STREAM with the status code FLOW_CONTROL_ERROR.
      *
    • Sender should ignore all WINDOW_UPDATE frames associated with a stream
    • after sending the last frame for the stream.
      */

    SPDYStreamId streamId = windowUpdateFrame.streamId;
    SPDY_DEBUG(@"received WINDOW_UPDATE.%u (+%lu)", streamId, (unsigned long)windowUpdateFrame.deltaWindowSize);

    if (streamId == kSPDYSessionStreamId) {
    // Check for numerical overflow
    if (_sessionSendWindowSize > INT32_MAX - windowUpdateFrame.deltaWindowSize) {
    [self _closeWithStatus:SPDY_SESSION_PROTOCOL_ERROR];
    return;
    }

    _sessionSendWindowSize += windowUpdateFrame.deltaWindowSize;
    for (SPDYStream *stream in _activeStreams) {
        [self _sendData:stream];
        if (_sessionSendWindowSize == 0) break;
    }
    
    return;
    

    }

    // Ignore frames for non-existent or half-closed streams
    SPDYStream *stream = _activeStreams[streamId];
    if (!stream || stream.localSideClosed) {
    return;
    }

    // Check for numerical overflow
    if (stream.sendWindowSize > INT32_MAX - windowUpdateFrame.deltaWindowSize) {
    [self _sendRstStream:SPDY_STREAM_FLOW_CONTROL_ERROR streamId:streamId];
    return;
    }

    stream.sendWindowSize += windowUpdateFrame.deltaWindowSize;
    [self _sendData:stream];
    }

if streamId is eqal to kSPDYSessionStreamId then _sessionSendWindowSize should be increased, but if not, stream.sendWindowSize should be increased instead. So only one sendWindowSize will be increased, not the both.

In _sendData:(SPDYStream *)stream function both of sendWindowSize were decreased at the same time:
_sessionSendWindowSize -= bytesSent;
stream.sendWindowSize -= bytesSent;
and in case of bytesSent equals 65536 bytes, they both equal 0.

Upon next call to the _sendData this line will always return 0:
uint32_t sendWindowSize = MIN(_sessionSendWindowSize, stream.sendWindowSize);

because only one sendWindowSize was increased in didReadWindowUpdateFrame.

So, a file with size more than 65536 bytes will never send.

@petroakzhygitov
Copy link
Author

Could you please, also, update CocoaPods with the latest 1.0.2 version? Now its 1.0.1

@CLAassistant
Copy link

CLAassistant commented Jul 18, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


petroakzhygitov seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants