http2: don't overflow stream IDs in server push

The max allowed stream ID is 2^31-1. The RFC says that we should send
GOAWAY if the ID space is exhausted.

Change-Id: I0042cb4e1f8781a2ece5a5f06f498eb06192da7f
Reviewed-on: https://go-review.googlesource.com/32488
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/http2/server.go b/http2/server.go
index bbe6396..79f4edf 100644
--- a/http2/server.go
+++ b/http2/server.go
@@ -2523,6 +2523,12 @@
 
 		// http://tools.ietf.org/html/rfc7540#section-5.1.1.
 		// Streams initiated by the server MUST use even-numbered identifiers.
+		// A server that is unable to establish a new stream identifier can send a GOAWAY
+		// frame so that the client is forced to open a new connection for new streams.
+		if sc.maxPushPromiseID+2 >= 1<<31 {
+			sc.goAwayIn(ErrCodeNo, 0)
+			return 0, ErrPushLimitReached
+		}
 		sc.maxPushPromiseID += 2
 		promisedID := sc.maxPushPromiseID