Re: Design Issue: Max Concurrent Streams Limit and Unidirectional Streams

James M Snell <jasnell@gmail.com> Fri, 26 April 2013 16:04 UTC

Return-Path: <ietf-http-wg-request@listhub.w3.org>
X-Original-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Delivered-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 4325221F9A3B for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Fri, 26 Apr 2013 09:04:39 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -10.392
X-Spam-Level:
X-Spam-Status: No, score=-10.392 tagged_above=-999 required=5 tests=[AWL=0.207, BAYES_00=-2.599, RCVD_IN_DNSWL_HI=-8]
Received: from mail.ietf.org ([12.22.58.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xSnRTcpLB-ad for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Fri, 26 Apr 2013 09:04:37 -0700 (PDT)
Received: from frink.w3.org (frink.w3.org [128.30.52.56]) by ietfa.amsl.com (Postfix) with ESMTP id 70E7D21F99DB for <httpbisa-archive-bis2Juki@lists.ietf.org>; Fri, 26 Apr 2013 09:04:37 -0700 (PDT)
Received: from lists by frink.w3.org with local (Exim 4.72) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1UVl7k-0006IQ-B0 for ietf-http-wg-dist@listhub.w3.org; Fri, 26 Apr 2013 16:03:48 +0000
Resent-Date: Fri, 26 Apr 2013 16:03:48 +0000
Resent-Message-Id: <E1UVl7k-0006IQ-B0@frink.w3.org>
Received: from lisa.w3.org ([128.30.52.41]) by frink.w3.org with esmtp (Exim 4.72) (envelope-from <jasnell@gmail.com>) id 1UVl7b-0006Hb-46 for ietf-http-wg@listhub.w3.org; Fri, 26 Apr 2013 16:03:39 +0000
Received: from mail-oa0-f44.google.com ([209.85.219.44]) by lisa.w3.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.72) (envelope-from <jasnell@gmail.com>) id 1UVl7Z-0005GD-TJ for ietf-http-wg@w3.org; Fri, 26 Apr 2013 16:03:39 +0000
Received: by mail-oa0-f44.google.com with SMTP id h1so4155078oag.17 for <ietf-http-wg@w3.org>; Fri, 26 Apr 2013 09:03:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=rDW4ZjUyZCuq9NeL4Y+0xP7RlHFRHRO2EoPyrBmk7lA=; b=PYt2yEbIfQcUe1GEph+xgxvUnJanAAioilJHHFfqpTHsOPGSzbza5+ID3WuCal1Z+k IiOW5jERXz22NlmyxYwky/Vi5DhOXSDL4dsncQ+Jg4NAyFzlJD0tHwOYHyyTwlOCEYJ9 bXysBBJrHiEJzesmvl54Ke7Mgg/7d65XiG8YEHvjGjo+iyQBkPTpwWybpwXaWQtFkGuY j4t44DifJ/MNqvs/JlA3uDwZiSS4DLkfJAI5DQPVtea4x8jswjh0lP3CqAS/QxFYryMW WhJfWgf//9/4s9DKSEdtugHp9S8u+ExjZkr3U05lLmJTLiGZHl8bWES/8KLqhr7OvO0F /ozg==
X-Received: by 10.60.47.84 with SMTP id b20mr3921356oen.135.1366992192045; Fri, 26 Apr 2013 09:03:12 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.60.3.137 with HTTP; Fri, 26 Apr 2013 09:02:51 -0700 (PDT)
In-Reply-To: <6C71876BDCCD01488E70A2399529D5E516416AA8@ADELE.crf.canon.fr>
References: <CABP7RbdBe-Xkx+CMvpN=_oNAqm6SyLyL+XNHRUKSqn8mjSDw1Q@mail.gmail.com> <CABkgnnW=Ve=9p2do5PncTVswTYCZqt-LMK50SYCKV1r8zEg=SQ@mail.gmail.com> <6C71876BDCCD01488E70A2399529D5E516416AA8@ADELE.crf.canon.fr>
From: James M Snell <jasnell@gmail.com>
Date: Fri, 26 Apr 2013 09:02:51 -0700
Message-ID: <CABP7Rbeh5zkS0nbWa_LhHKR9LhNW1aRbG-KW7mMKcyh2_cwGXg@mail.gmail.com>
To: RUELLAN Herve <Herve.Ruellan@crf.canon.fr>
Cc: Martin Thomson <martin.thomson@gmail.com>, "ietf-http-wg@w3.org" <ietf-http-wg@w3.org>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass client-ip=209.85.219.44; envelope-from=jasnell@gmail.com; helo=mail-oa0-f44.google.com
X-W3C-Hub-Spam-Status: No, score=-3.5
X-W3C-Hub-Spam-Report: AWL=-2.689, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001
X-W3C-Scan-Sig: lisa.w3.org 1UVl7Z-0005GD-TJ aa5cf16baa5a29a751a7c17e0c5402bf
X-Original-To: ietf-http-wg@w3.org
Subject: Re: Design Issue: Max Concurrent Streams Limit and Unidirectional Streams
Archived-At: <http://www.w3.org/mid/CABP7Rbeh5zkS0nbWa_LhHKR9LhNW1aRbG-KW7mMKcyh2_cwGXg@mail.gmail.com>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/17606
X-Loop: ietf-http-wg@w3.org
Resent-Sender: ietf-http-wg-request@w3.org
Precedence: list
List-Id: <ietf-http-wg.w3.org>
List-Help: <http://www.w3.org/Mail/>
List-Post: <mailto:ietf-http-wg@w3.org>
List-Unsubscribe: <mailto:ietf-http-wg-request@w3.org?subject=unsubscribe>

On Fri, Apr 26, 2013 at 3:30 AM, RUELLAN Herve
<Herve.Ruellan@crf.canon.fr> wrote:
> I've got the feeling that we should limit in some way the number of promised streams: too many promised streams could hurt an intermediary.
>

The more I think it over (sleeping on the problem helped) the more I
think that the idea of redefining SETTINGS_MAX_CONCURRENT_STREAMS and
adding a separate SETTINGS_OPEN_STREAMS_CREDIT makes the most sense
here. It effectives gives us two distinct and flexible control points.

SETTINGS_MAX_CONCURRENT_STREAMS would set an upper limit on the number
of outbound open streams an endpoint can have at any given time.
SETTINGS_OPEN_STREAMS_CREDIT provides an upper limit on the total
number of open streams (or half-open in any direction) an endpoint can
initiate. Rather than being a hard limit, however, the recipient, if
it wishes, can allow the sender to overdraw on its credit. If the
recipient is concerned that the sender is misbehaving, flow control
mechanism can be used by the recipient to tell the sender to slow down
or stop, or it can simply choose to reject all new streams.

Example 1: Client to Sender

Client opens the connection, Server tells the client that they have a
MAX_CONCURRENT_STREAMS of 10, OPEN_STREAMS_CREDIT of 20. This means
that the browser cannot initiate more than 10 open streams at a time.
If it creates 10, then half-closes 5, it can open another five
streams. It's OPEN_STREAMS_CREDIT counter would then be at 15 until
the server half-closes items on it's end. Let's say the client
half-closes five more streams and opens another five. It's still
within it's MAX_CONCURRENT_STREAMS limit, but if the server has not
half-closed any of those streams, the client will have reached it's
OPEN_STREAMS_CREDIT limit. The recipient now has a choice: A) it can
choose to allow the client to continue opening streams, B) it can
choose to use flow-control to tell the client to chill out and slow
down, C) it can hold off on responding to newly initiated stream until
the server has had a chance to half close, or D) it can reject the new
streams with an error. If the client continues to overdraw on it's
open streams credit limit, the recipient can choose to take more
drastic action such as terminating the session.

Example 2: Sender to Client

Client opens the connection and opens a stream to the server. The
client tells the server that it has a MAX_CONCURRENT_STREAMS of 10,
and an OPEN_STREAMS_CREDIT of 20. The server sends 10 PUSH_PROMISES to
the client. These count towards the MAX_CONCURRENT_STREAMS limit and
the OPEN_STREAMS_CREDIT. Once the server half-closes a pushed stream,
it can send another PUSH_PROMISE, but unless the recipient
half-closes, it still counts against their open streams credit limit.
Once that limit is reached, the recipient has the same choices as
above.

Yes, there is a denial of service risk here, but it's no worse than
what we currently have.

- James


> One way to do this is to say that a PUSH_PROMISE creates a new stream. In this way it is counted against the SETTINGS_MAX_CONCURRENT_STREAMS. We would also have to mandate a client to half-close all PUSH_PROMISE streams.
>
>
> While reading the current spec, my understanding on whether a PUSH_PROMISE created a new stream wandered back and forth, and I think some clarification could be useful.
>
> In particular the first paragraph of 3.4.1:
> "There is no coordination or shared action between the client and server required to create a stream. Rather, new streams are established by sending a frame that references a previously unused stream identifier."
>
> The "Promised-Stream-ID" of the PUSH_PROMISE frame could be considered as being the reference to an unused stream identifier, therefore creating the stream.
>
> The rest of 3.4.1 and 3.8.5 on the contrary say that a PUSH_PROMISE frame doesn't create a new stream.
>
> I would propose the following edit to this first paragraph of 3.4.1:
> "There is no coordination or shared action between the client and server required to create a stream. Rather, new streams are established by sending a frame that references in its "Stream Identifier" field a previously unused stream identifier."
>
> Hervé.
>
>> -----Original Message-----
>> From: Martin Thomson [mailto:martin.thomson@gmail.com]
>> Sent: jeudi 25 avril 2013 21:26
>> To: James M Snell
>> Cc: ietf-http-wg@w3.org
>> Subject: Re: Design Issue: Max Concurrent Streams Limit and Unidirectional
>> Streams
>>
>> On 25 April 2013 10:50, James M Snell <jasnell@gmail.com> wrote:
>> > https://github.com/http2/http2-spec/issues/78
>> >...
>> > If a client sets a limit of 4 concurrent streams, and the server
>> >initiates 4 separate PUSH_PROMISE streams that the server half-closes
>> >but that are never half-closed by the client, the server will not be
>> >able to initiate new push streams for the duration of the session.
>>
>> Yep, it's a problem.  We got rid of the unidirectional flag that addressed this.  I
>> can't speak for others, but I was aware of the issue at the time, but I had a
>> solution in mind.  That never got written down, partly because we didn't
>> have this discussion :)
>>
>> On first blush, the only way to avoid the problem is to expect the framing
>> layer to be aware of what is going on above, but that's probably not sensible.
>> But there's a better way:
>>
>> Each stream has two separate state variables, each with three state
>> values: no packet yet, open, half-closed.  Streams that have inbound ==
>> open || outbound == open are "in use" and count toward the stream limit.
>> Documenting this might help clarify how the accounting is done.
>>
>> Importantly, this means that promised streams do not count toward the
>> limit.  It does however also imply that implementations will need to be
>> careful about how they allocate stream resources.  Pushes complicate that a
>> little because the lifecycle of headers doesn't match stream lifecycles.  Again,
>> I'd suggest an approach where implementations defer commitment of flow
>> control buffers until the first flow-controlled frame arrives (memory pre-
>> allocation might be advisable for performance reasons, but that would not be
>> an actual
>> commitment) and to ensure that any state for send and receive don't have
>> the same lifecycle.
>