Re: Stream State and PRIORITY Frames

Cory Benfield <cory@lukasa.co.uk> Tue, 17 January 2017 12:46 UTC

Return-Path: <ietf-http-wg-request+bounce-httpbisa-archive-bis2juki=lists.ie@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 0B1001270B4 for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Tue, 17 Jan 2017 04:46:02 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -9.619
X-Spam-Level:
X-Spam-Status: No, score=-9.619 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, RP_MATCHES_RCVD=-3.199, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=lukasa-co-uk.20150623.gappssmtp.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s9HydfDaQLsv for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Tue, 17 Jan 2017 04:45:59 -0800 (PST)
Received: from frink.w3.org (frink.w3.org [128.30.52.56]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 34BBE129AA1 for <httpbisa-archive-bis2Juki@lists.ietf.org>; Tue, 17 Jan 2017 04:45:59 -0800 (PST)
Received: from lists by frink.w3.org with local (Exim 4.80) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1cTT6w-0004xX-Ux for ietf-http-wg-dist@listhub.w3.org; Tue, 17 Jan 2017 12:43:38 +0000
Resent-Date: Tue, 17 Jan 2017 12:43:38 +0000
Resent-Message-Id: <E1cTT6w-0004xX-Ux@frink.w3.org>
Received: from mimas.w3.org ([128.30.52.79]) by frink.w3.org with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from <cory@lukasa.co.uk>) id 1cTT6t-0004wU-PE for ietf-http-wg@listhub.w3.org; Tue, 17 Jan 2017 12:43:35 +0000
Received: from mail-wm0-f45.google.com ([74.125.82.45]) by mimas.w3.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <cory@lukasa.co.uk>) id 1cTT6n-0004aR-4l for ietf-http-wg@w3.org; Tue, 17 Jan 2017 12:43:30 +0000
Received: by mail-wm0-f45.google.com with SMTP id c85so198318684wmi.1 for <ietf-http-wg@w3.org>; Tue, 17 Jan 2017 04:43:08 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lukasa-co-uk.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=Kz7dHvZUCLmsLQrRLkGmjSvA0u/2WxN7j7o/OC8j0Gg=; b=hT/Kq5seEtAmdN1ps1Q26sFeHqXN7DAnvJhTxZzQ4r9V+xJapu14Av85xnlrmXddCq M6IIRW42jhk4z5emO8b9bCj3H/NsMHvKA1+7ix12zO9k2WdiC3IB4tiHVXXjdz6km37k H3EqhBM6PWB2913M168SpnOUfkGqGgsHqkRpxdJGYfoohEBKyxnYfgS2NsfwsVcEsDxy BB24PtuwCRfLWkZ6KylRTOIl1IJwcBXdSJt+teAkRFgJrgKPnRseemY9qnh6FfQAI5dK cviBdACKY6vGE7+TVzQ0gZoH5W5ozgzFLJDqdh+nG1r6rEqGZ32X9FlB4ZTLwwHLmUfA eCFQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=Kz7dHvZUCLmsLQrRLkGmjSvA0u/2WxN7j7o/OC8j0Gg=; b=csblznh1kp2NKX7qoIMc9oFm9UeLc4JGs4UQChhL0QnyvIsaRywR0/SIHlXwl0IwIP 2t3g7cRZsBKiIc2l8jnqkbR8VX1g6OlIhagICiRIVa8aE+a5HhzMx5acc+gZJeL0pJsB Bu2xOyhskCS3wxmZeOPV4da+T/CzR7257ZhvbYo39ZSxO/G9I6HptcfDH5yTNU3JxfFd hl/IXuwsSZsFDSqwA1mv9HKuRKBaDtWrd1kJ5v9miS79ncAWd02zDaV0GUYk62227nwx D2Tz3Ary9Da3u2SHrVhrSxZiE08U6bRAPTq/nQPpJU/Qj9OAe1ocByx9VWFh/Yi/mloB Xnjg==
X-Gm-Message-State: AIkVDXKEvZUXkgr9K/Peb2ZW5/4qKynu+HL/divL4G8Jmk+XQYe08ABAKg0QptwhML4AOw==
X-Received: by 10.223.133.4 with SMTP id 4mr19115033wrh.176.1484656982043; Tue, 17 Jan 2017 04:43:02 -0800 (PST)
Received: from [192.168.1.5] (178.64.6.51.dyn.plus.net. [51.6.64.178]) by smtp.gmail.com with ESMTPSA id r6sm36678521wmd.4.2017.01.17.04.42.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2017 04:43:00 -0800 (PST)
From: Cory Benfield <cory@lukasa.co.uk>
Message-Id: <2BC01E49-91A1-43A7-AFD0-5A34F2689428@lukasa.co.uk>
Content-Type: multipart/alternative; boundary="Apple-Mail=_73B57978-A80C-4AB0-9CB9-EC830D81AF17"
Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\))
Date: Tue, 17 Jan 2017 12:42:58 +0000
In-Reply-To: <CAGZNdJWe0Y=M_SWmgYabKbWZwPEuJdw67Km8+UtR4oUtZuXA5A@mail.gmail.com>
Cc: Scott Mitchell <scott.k.mitch1@gmail.com>, HTTP Working Group <ietf-http-wg@w3.org>
To: Benedikt Christoph Wolters <benedikt.wolters@rwth-aachen.de>
References: <CAFn2buAYWHQSWhhoKZ2GKbqXR1A+tScjkAwZmOuQ9gV9jMp2bA@mail.gmail.com> <CAGZNdJWe0Y=M_SWmgYabKbWZwPEuJdw67Km8+UtR4oUtZuXA5A@mail.gmail.com>
X-Mailer: Apple Mail (2.3259)
Received-SPF: pass client-ip=74.125.82.45; envelope-from=cory@lukasa.co.uk; helo=mail-wm0-f45.google.com
X-W3C-Hub-Spam-Status: No, score=-4.8
X-W3C-Hub-Spam-Report: AWL=-1.408, BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001, W3C_AA=-1, W3C_WL=-1
X-W3C-Scan-Sig: mimas.w3.org 1cTT6n-0004aR-4l 0dabdae9b6217d875ceb712ea941dbd6
X-Original-To: ietf-http-wg@w3.org
Subject: Re: Stream State and PRIORITY Frames
Archived-At: <http://www.w3.org/mid/2BC01E49-91A1-43A7-AFD0-5A34F2689428@lukasa.co.uk>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/33304
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 17 Jan 2017, at 08:38, Benedikt Christoph Wolters <benedikt.wolters@rwth-aachen.de> wrote:
> 
> This question reminds me of a similiar issue we had a while ago at
> mitmproxy: https://github.com/mitmproxy/mitmproxy/issues/1498
> 
> As far as I understand this, sending PRIORITY does not initiate a
> stream or change the stream state.
> HEADERS and PUSH_PROMISE initiate a stream. PRIORITY can be sent and
> received in any stream state.

In fact, I think it’s the same issue. Scott linked to https://github.com/summerwind/h2spec/pull/67 <https://github.com/summerwind/h2spec/pull/67>, which is referenced from and opened by the same person who opened https://github.com/h2o/h2o/pull/1136 <https://github.com/h2o/h2o/pull/1136>, which links to https://github.com/mitmproxy/mitmproxy/issues/1824 <https://github.com/mitmproxy/mitmproxy/issues/1824>, which is related to https://github.com/mitmproxy/mitmproxy/issues/1498 <https://github.com/mitmproxy/mitmproxy/issues/1498> because both cases were sites deployed behind Fastly.

For those who want background and don’t want to follow all those links, mitmproxy bumped into problems with sites deployed behind Fastly. mitmproxy encountered these because it was forwarding on traffic from Firefox, which would on connection-setup send a whole bunch of PRIORITY frames. hyper-h2 (which powers mitmproxy’s HTTP/2 support) would allow this. h2o would not.

The crux of the discussion boils down to a few apparently contradictory sections in the specification. Scott linked to the first two:

Section 5.1.1:

- The first use of a new stream identifier implicitly closes all streams in the “idle” state that may have been initiated by that peer with a lower-valued stream identifier.
- An endpoint that receives an unexpected stream identifier must respond with a connection error of type PROTOCOL_ERROR.

*However*, there are a few other notes. The first thing to note is that the PRIORITY frame does not transition a stream out of the idle state. A stream that has only had PRIORITY frames sent on it is still in the IDLE state. That means that the Firefox-style priority setup (sending priority for stream IDs 1, 3, 5, and 7 immediate after the preamble) would have the effect of immediately closing streams 1, 3, and 5, if section 5.1.1 applied. This is not what most people expect.

More importantly, though, section 5.1.1 says this:

- The identifier of a newly established stream MUST be numerically greater than all streams that the initiating endpoint has opened or reserved. This governs streams that are opened using a HEADERS frame and streams that are reserved using PUSH_PROMISE.

This is not absolutely clear, but it seems to suggest that implementations may establish a stream with an ID lower than streams that have had PRIORITY frames sent on them. Put another way, it seems to suggest that only HEADERS and PUSH_PROMISE frames affect the lowest-acceptable stream ID. That seems to me to suggest that PRIORITY frames are not expected to force-close all streams with lower IDs that are in the idle state.

As an implementers note, I have found it much more helpful to think of PRIORITY frames not as frames that are sent on a stream, but as frames that are implicitly sent on stream zero and are just tagged with a stream ID. PRIORITY frames ignore basically all restrictions on stream behaviour: they can be sent on idle streams, on closed streams. In practice, they can basically be sent whenever, and except for the case where they establish a loop in the priority tree must basically always be accepted.

Cory